home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++Source Code Fmtr Folder / Tests / UDialog.cp < prev    next >
Encoding:
Text File  |  1991-01-10  |  98.2 KB  |  3,741 lines  |  [TEXT/MPS ]

  1. //$P
  2. //[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]
  3. // UDDialog.inc1.p 
  4. /* Copyright © 1988-1990 Apple Computer Inc. All rights reserved. */
  5.  
  6. #include "MacApp.h"
  7. #include "ToolUtils.h"    //GetIndString
  8. #include "Resources.h"    //GetResource
  9. #include "Packages.h"    //StringToNum
  10. #include "Sane.h"        //Decimal
  11. #include "Strings.h"   //p2cstr
  12.  
  13. //RCR    UList, UAssociation, Editions, Dialogs, UApplication, UDocument, UWindow, UScroller,
  14. //RCR     UFailure, UMacAppUtilities, UErrorMgr, UPatch, UMacAppGlobals, Errors, UPopUp, SysEqu, Traps,
  15. //RCR     Devices, ULoMem, UViewCoords, Menus, UMenuMgr, Sane, Script, ToolUtils, Packages, Resources,
  16. //RCR     UAdorners();
  17.  
  18.     TAssociation*        gParamTxt;            // Used for text substitution 
  19.     TDialogTEView*        gFloatingTEView;    // The floating TEView used with edit text fields. 
  20.  
  21. //--------------------------------------------------------------------------------------------------
  22. #pragma segment DlgInit
  23.  
  24. pascal void InitUDialog(void)
  25.  
  26.     {
  27.     if (qTemplateViews)
  28.         {
  29.         // So the linker doesn't dead strip these 
  30.         DontDeadStrip(TDialogView);
  31.         DontDeadStrip(TControl);
  32.         DontDeadStrip(TButton);
  33.         DontDeadStrip(TCheckBox);
  34.         DontDeadStrip(TRadio);
  35.         DontDeadStrip(TCluster);
  36.         DontDeadStrip(TIcon);
  37.         DontDeadStrip(TPicture);
  38.         DontDeadStrip(TPopup);
  39.         DontDeadStrip(TStaticText);
  40.         DontDeadStrip(TEditText);
  41.         DontDeadStrip(TNumberText);
  42.         DontDeadStrip(TPattern);
  43.  
  44.         RegisterStdType("TDialogView", kStdDialogView);
  45.         RegisterStdType("TControl", kStdControl);
  46.         RegisterStdType("TButton", kStdButton);
  47.         RegisterStdType("TCheckBox", kStdCheckBox);
  48.         RegisterStdType("TRadio", kStdRadio);
  49.         RegisterStdType("TCluster", kStdCluster);
  50.         RegisterStdType("TIcon", kStdIcon);
  51.         RegisterStdType("TPicture", kStdPicture);
  52.         RegisterStdType("TPopup", kStdPopup);
  53.         RegisterStdType("TStaticText", kStdStaticText);
  54.         RegisterStdType("TEditText", kStdEditText);
  55.         RegisterStdType("TNumberText", kStdNumberText);
  56.         RegisterStdType("TPattern", kStdPattern);
  57.         }
  58.  
  59.         gFloatingTEManager = new TFloatingTEManager;
  60.         gFloatingTEManager->IObject();        
  61.  
  62.     
  63.         /*!!! Create the dictionary for the global text substitution mechanism. 
  64.             This should move out of UDialog soon */
  65.         
  66.         gParamTxt = new TAssociation;                                 
  67.         gParamTxt->IAssociation();
  68.  
  69.     
  70.     
  71.     gUDialogInitialized = TRUE;
  72.     }
  73.  
  74.  
  75. //--------------------------------------------------------------------------------------------------
  76. #pragma segment DlgRes
  77. pascal TDialogTEView* AquireFloatingTEView()
  78. {
  79.     if (gFloatingTEManager != NULL)
  80.         return (gFloatingTEManager->AquireFloatingTE());
  81.     else
  82.         return NULL;
  83. }
  84.  
  85. //--------------------------------------------------------------------------------------------------
  86. #pragma segment DlgRes
  87. pascal void ReleaseFloatingTEView(TDialogTEView* aDialogTEView)
  88. {
  89.     if (gFloatingTEManager != NULL)
  90.         gFloatingTEManager->ReleaseFloatingTE(aDialogTEView);
  91. }
  92.  
  93. //--------------------------------------------------------------------------------------------------
  94. #pragma segment DlgRes
  95.  
  96. pascal void MAParamText(const Str255& keyStr, const Str255& valueStr)
  97.  
  98. {
  99.     gParamTxt->InsertEntry(keyStr, valueStr);
  100. }
  101.  
  102. //--------------------------------------------------------------------------------------------------
  103. #pragma segment DlgRes
  104.  
  105. //RCR Iteration object
  106. typedef pascal void (*DoToEntryType) (TEntry* anEntry, void* staticLink) ;
  107. typedef pascal void (*DoToObjectType) (TObject* anEntry, void* staticLink) ;
  108.  
  109. class CReplaceOnce 
  110. {
  111.     Str255& fTheText;
  112. public:    
  113.     // Constructor
  114.     CReplaceOnce(Str255& theText):fTheText (theText) {};
  115.     
  116.     pascal void ReplaceOnce(TEntry* anEntry);
  117. };
  118.  
  119. #pragma segment DlgRes
  120.  
  121. pascal void CReplaceOnce::ReplaceOnce(TEntry* anEntry)
  122. {
  123. /*RCR
  124.     do 
  125.     {
  126.         short    index;
  127.         
  128.         index = Pos(**(anEntry->fKey), theText);
  129.         if (index > 0)
  130.         {
  131.         Delete(theText, index, Length(**(anEntry->fKey);
  132.         if (Length(theText) + Length(**(anEntry->fValue)) < sizeof(Str255))
  133.             Insert(**(anEntry->fValue), theText, index);
  134.         }
  135.     } 
  136.     while (index != 0);
  137. */
  138. }
  139.  
  140. #pragma segment DlgRes
  141.  
  142. pascal void MAReplaceText(Str255& theText)
  143. {
  144.     CReplaceOnce aCReplaceOnce(theText);
  145.  
  146.     gParamTxt->fEntries->Each((DoToObjectType) &CReplaceOnce::ReplaceOnce,&aCReplaceOnce);
  147. }
  148.  
  149. //--------------------------------------------------------------------------------------------------
  150. #pragma segment DlgOpen
  151.  
  152. pascal void TDialogView::Initialize(void) // override 
  153. {
  154.     inherited::Initialize();
  155.  
  156. #if qDebug
  157.     if (!gUDialogInitialized)
  158.     {
  159.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  160.         Failure(noErr, 0);
  161.     }
  162. #endif
  163.  
  164.     fDefaultItem = kNoIdentifier;
  165.     fCancelItem = kNoIdentifier;
  166.     fDismisser = kNoIdentifier;
  167. }
  168.  
  169. //--------------------------------------------------------------------------------------------------
  170. #pragma segment DlgOpen
  171.  
  172. pascal void TDialogView::IDialogView(TDocument* itsDocument,
  173.                                        TView*        itsSuperView,
  174.                                        const VPoint&    itsLocation, 
  175.                                        const VPoint& itsSize,
  176.                                        SizeDeterminer itsHSizeDet, 
  177.                                      SizeDeterminer itsVSizeDet,
  178.                                        const IDType itsDefItemID, 
  179.                                      const IDType itsCancelItemID)
  180.  
  181. {
  182. #if qDebug
  183.     if (!gUDialogInitialized)
  184.         {
  185.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  186.         Failure(noErr, 0);
  187.         }
  188. #endif
  189.  
  190.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  191.  
  192.     fDefaultItem = itsDefItemID;
  193.     fCancelItem = itsCancelItemID;
  194.  
  195.     }
  196.  
  197. //--------------------------------------------------------------------------------------------------
  198. #pragma segment DlgOpen
  199.  
  200. pascal void TDialogView::IRes(TDocument* itsDocument,
  201.                                  TView* itsSuperView,
  202.                                 Ptr& itsParams) // override 
  203.  
  204. {
  205. #if qDebug
  206.     if (!gUDialogInitialized)
  207.         {
  208.         ProgramBreak("InitUDialog must be called before creating a Dialog View.");
  209.         Failure(noErr, 0);
  210.         }
  211. #endif
  212.  
  213.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  214.  
  215.     DialogViewTemplate& templateData = (DialogViewTemplate&) *itsParams;
  216.     fDefaultItem = templateData.defaultItem;
  217.     fCancelItem = templateData.cancelItem;
  218.  
  219.     OffsetPtr(itsParams, sizeof(DialogViewTemplate));
  220. }
  221.  
  222. //--------------------------------------------------------------------------------------------------
  223. #pragma segment DlgRes
  224.  
  225. pascal TObject* TDialogView::Clone(void) // override 
  226.  
  227.     {
  228.         TDialogView*        aClonedDialogView;
  229.  
  230.     
  231.     aClonedDialogView = (TDialogView*)(inherited::Clone());
  232.     
  233.  
  234.     return aClonedDialogView;
  235.     }
  236.  
  237. //--------------------------------------------------------------------------------------------------
  238. #pragma segment MAWriteRes
  239.  
  240. pascal void TDialogView::WRes(ViewRsrcHandle theResource,
  241.                                  Ptr& itsParams) // override 
  242. {
  243.     inherited::WRes(theResource, itsParams);
  244.  
  245.     DialogViewTemplate&    templateData =
  246.         (DialogViewTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(DialogViewTemplate)));
  247.  
  248.     templateData.defaultItem = fDefaultItem;
  249.     templateData.cancelItem = fCancelItem;
  250. }
  251.  
  252. //--------------------------------------------------------------------------------------------------
  253. #pragma segment MAWriteRes
  254.  
  255. pascal void TDialogView::WriteRes(ViewRsrcHandle theResource,
  256.                                      Ptr& itsParams) // override 
  257.  
  258.     {
  259.     gWResSignature = 'dlog'; gWResType = "TDialogView";
  260.     this->WRes(theResource, itsParams);
  261.     }
  262.  
  263. //--------------------------------------------------------------------------------------------------
  264. #pragma segment DlgClose
  265.  
  266. pascal void TDialogView::Free(void) // override 
  267.  
  268.     {
  269.  
  270.     inherited::Free();
  271.  
  272.     }
  273.  
  274. //--------------------------------------------------------------------------------------------------
  275. #pragma segment DlgRes
  276.  
  277. pascal Boolean TDialogView::CanDismiss(const IDType dismissing)
  278.  
  279.     {
  280.         TView*        dismissingView;
  281.         Boolean        successful;
  282.  
  283.     
  284.     // First, make sure the view initiating the the dismissal, if any, is enabled. 
  285.  
  286.     if (((long) dismissing) != ((long) kNoIdentifier))
  287.         dismissingView = FindSubView(dismissing);
  288.     else
  289.         dismissingView = NULL;                            // no dismissing view 
  290.  
  291.     // Thanks Tommi GESSL 
  292.     successful = (dismissingView == NULL) || (dismissingView->IsEnabled());
  293.  
  294.     if (successful)                                    /* test only we haven´t failed */
  295.         /* Now, if we're not cancelling, make sure the current edit text is valid and
  296.         return false if it isn't.*/
  297.  
  298.         if ( ( (long) fCancelItem == (long) kNoIdentifier ) || (dismissing != fCancelItem) )
  299.         {
  300.             this->DoSelectEditText(NULL, False);                // Attempt to deselect current edit text 
  301.             return (this->GetCurrentEditText() == NULL);        // Successful only if it was deselected 
  302.         }
  303.         else
  304.             return (successful);
  305.     }
  306.  
  307. //--------------------------------------------------------------------------------------------------
  308. #pragma segment DlgClose
  309.  
  310. pascal void TDialogView::Close(void) // override 
  311.  
  312.     {
  313.     if (((long)fDismisser) == ((long)kNoIdentifier))
  314.         this->DismissDialog(kNoIdentifier);
  315.  
  316.     inherited::Close();
  317.     }
  318.  
  319. //--------------------------------------------------------------------------------------------------
  320. #pragma segment DlgRes
  321.  
  322. pascal Boolean TDialogView::DeselectCurrentEditText(void)
  323. {
  324.     TEditText*    currentEditText;
  325.     Boolean        result;
  326.  
  327.     result = TRUE;
  328.     currentEditText = this->GetCurrentEditText();
  329.     if ((currentEditText != NULL) && (currentEditText->fTEView != NULL))
  330.     {
  331.         result = (currentEditText->fTEView->WillingToResignTarget() == kValidValue);
  332.         this->BeTarget();
  333.     }
  334.     return result;
  335. }
  336.  
  337. //--------------------------------------------------------------------------------------------------
  338. #pragma segment DlgClose
  339.  
  340. pascal void TDialogView::DismissDialog(const IDType dismisser)
  341.  
  342.     {
  343.         TWindow*    itsWindow;
  344.  
  345.     
  346.     itsWindow = this->GetWindow();
  347.     if (!itsWindow->IsDismissed())
  348.         if (this->CanDismiss(dismisser))
  349.             {
  350.             itsWindow->Dismiss();
  351.             fDismisser = dismisser;
  352.             }        
  353.         else
  354.             Failure(noErr, 0);                            // Silent failure 
  355.     }
  356.  
  357. //--------------------------------------------------------------------------------------------------
  358. #pragma segment DlgRes
  359.  
  360. pascal void TDialogView::HandleEvent(EvtNumber eventNumber,
  361.                                     TEvtHandler*        source,
  362.                                     TEvent* event) // override 
  363.  
  364. {
  365.     switch (eventNumber) 
  366.     {
  367.         case mEditTextHit:
  368. #if qDebug
  369.             if (! source->IsMemberClass(GetClassIDFromName("TEditText")))
  370.                 ProgramBreak("Got mEditTextHit on non-TEditText view.");
  371.             else
  372. #endif
  373. //!!!RCR
  374. #if FALSE
  375.                 DoSelectEditText((TEditText*) source), False);
  376. #endif
  377.             break;
  378.         default:
  379.             if ( source->IsMemberClass(GetClassIDFromName("TControl")) && ((TControl*) source)->fDismissesDialog )
  380.                  DismissDialog(((TView*) source)->fIdentifier) ;
  381.             else
  382.                 inherited::HandleEvent(eventNumber,source,event);
  383.             break;
  384.     }
  385. }
  386.  
  387. //--------------------------------------------------------------------------------------------------
  388. #pragma segment DlgRes
  389.  
  390. pascal void TDialogView::DoCommandKey(TDeviceEvent* event) // override 
  391.  
  392.     {
  393.         TView*        cancelView;
  394.  
  395.     
  396.     //!!! this needs internationalization 
  397.     if ( this->IsEnabled() && event->fCharacter == '.' && ( (long) fCancelItem != (long) kNoIdentifier) )
  398.         {
  399.         cancelView = this->FindSubView(fCancelItem);
  400.         if (cancelView != NULL)
  401.             {
  402.             if ( cancelView->IsMemberClass(GetClassIDFromName("TControl")) )
  403.                 cancelView->HandleEvent(((TControl*) cancelView)->fDefChoice, this,NULL);
  404.             else
  405.                 cancelView->HandleEvent(mCancelKey, this,NULL);
  406.             }        
  407.         else
  408.             this->HandleEvent(mCancelKey, this,NULL);
  409.         }    
  410.     else
  411.         inherited::DoCommandKey(event);
  412.     }
  413.  
  414. //--------------------------------------------------------------------------------------------------
  415. #pragma segment DlgRes
  416.  
  417. pascal void TDialogView::DoKeyCommand(TDeviceEvent* event) // override 
  418. {
  419.     TView*        defaultView;
  420.     TView*        cancelView;
  421.  
  422.     
  423.     // If we get this far, nobody's handled the Tab, Enter, or Return keys, so we will  
  424.     if (this->IsEnabled())
  425.     {
  426.         switch (event->fCharacter)
  427.         {
  428.             case chEscape:
  429.                 if (event->fKeyCode == kClearVirtualCode)    // esc double for two different keys! 
  430.                     inherited::DoKeyCommand(event);
  431.                 else if (((long)fCancelItem) != ((long)kNoIdentifier))
  432.                     {
  433.                     cancelView = FindSubView(fCancelItem);
  434.                     if (cancelView != NULL)
  435.                         {
  436.                         if (cancelView->IsMemberClass(GetClassIDFromName("TControl")))
  437.                             cancelView->HandleEvent( ((TControl*) cancelView)->fDefChoice, cancelView, NULL);
  438.                         else
  439.                             cancelView->HandleEvent(mCancelKey, cancelView, NULL);
  440.                         }                    
  441.                     else
  442.                         this->HandleEvent(mCancelKey, this, NULL);
  443.                     }                
  444.                 else
  445.                     inherited::DoKeyCommand(event);
  446.                 break;
  447.             case chTab:
  448.                 TabTarget(event->fShiftKey,TRUE); 
  449.                 break;
  450.             case chEnter:
  451.             case chReturn:
  452.                 if ( (long) fDefaultItem != (long) kNoIdentifier )
  453.                     {
  454.                     defaultView = FindSubView(fDefaultItem);
  455.                     if (defaultView != NULL)
  456.                         {
  457.                         if (defaultView->IsMemberClass(GetClassIDFromName("TControl")))
  458.                             defaultView->HandleEvent( ((TControl*) defaultView)->fDefChoice, defaultView, NULL);
  459.                         else
  460.                             defaultView->HandleEvent(mDefaultKey, defaultView, NULL);
  461.                         }                    
  462.                     else
  463.                         this->HandleEvent(mDefaultKey, this, NULL);
  464.                     }                
  465.                 else
  466.                     inherited::DoKeyCommand(event);
  467.                 break;
  468.             default:
  469.                 inherited::DoKeyCommand(event);
  470.         }
  471.     }
  472.     else
  473.         inherited::DoKeyCommand(event);
  474. }
  475.  
  476. //--------------------------------------------------------------------------------------------------
  477. #pragma segment DlgRes
  478.  
  479. pascal void TDialogView::DoSelectEditText(TEditText* theEditText,
  480.                                              Boolean selectChars)
  481. {
  482.  
  483.     if (theEditText != this->GetCurrentEditText())         // If we're not editing this view… 
  484.     {
  485.         if (theEditText == NULL)
  486.             this->BeTarget();                            // Set the window's target to self 
  487.         else 
  488.         {
  489.             if (theEditText->IsEnabled())
  490.                 theEditText->StartEdit(selectChars);
  491. #if qDebug
  492.             else
  493.                 ProgramBreak("Attempt to select a disabled edit text view")
  494. #endif
  495.                 ;
  496.         }
  497.     }    
  498.     else
  499.         if (selectChars && (theEditText != NULL))         // Make sure all the chars are selected. 
  500.             theEditText->SetSelection(0, MAXINT, kRedraw);
  501. }
  502.  
  503. //--------------------------------------------------------------------------------------------------
  504. #pragma segment DlgRes
  505.  
  506. //RCR Iteration object for EachEditText
  507.  
  508. typedef pascal void (*DoToViewType) (TView* , void* staticLink) ;
  509. typedef pascal void (*DoToEditTextType) (TEditText* , void* staticLink) ;
  510.  
  511. class CCheckSubView
  512. {
  513.     const void*&             fStaticLink;
  514.     const DoToEditTextType&    fDoToEditText;
  515. public:
  516.     // Constructor
  517.     CCheckSubView(const DoToEditTextType DoToEditText,void* staticLink)
  518.         :fDoToEditText (DoToEditText),fStaticLink (staticLink) {};
  519.  
  520.     pascal void CheckSubView(TView* theSubView);
  521. };
  522.  
  523. #pragma segment DlgRes
  524.  
  525. pascal void CCheckSubView::CheckSubView(TView* theSubView)
  526. {
  527. if (theSubView->IsMemberClass(GetClassIDFromName("TEditText")))
  528.     fDoToEditText( (TEditText*) theSubView, fStaticLink);
  529. else
  530.     {
  531.     CCheckSubView aCCheckSubView(fDoToEditText,fStaticLink);
  532.     
  533.     theSubView->EachSubView((DoToViewType) &CCheckSubView::CheckSubView,&aCCheckSubView);
  534.     }
  535. };
  536.  
  537. #pragma segment DlgRes
  538.  
  539. pascal void TDialogView::EachEditText(DoToEditTextType DoToEditText, void *staticLink)
  540. {
  541.     CCheckSubView aCCheckSubView(DoToEditText,staticLink);
  542.  
  543.     this->EachSubView((DoToViewType) &CCheckSubView::CheckSubView,&aCCheckSubView);
  544. }
  545.  
  546. //--------------------------------------------------------------------------------------------------
  547. #pragma segment DlgRes
  548. pascal TEditText* TDialogView::GetCurrentEditText(void)
  549. {
  550.     TEvtHandler*    currentTarget;
  551.     TWindow*        myWindow;
  552.     TEditText*        result;
  553.  
  554. //!!!RCR Needs work
  555.     result = NULL;
  556.     myWindow = this->GetWindow();
  557.     if (myWindow != NULL)
  558.         currentTarget = myWindow->GetTarget();
  559.     else 
  560.         currentTarget = NULL;
  561.     if ((currentTarget != NULL) && currentTarget->IsMemberClass(GetClassIDFromName("TDialogTEView")) )
  562.         result = ((TDialogTEView*) currentTarget)->fEditText;
  563.     return result;
  564. }
  565.  
  566.  
  567. //--------------------------------------------------------------------------------------------------
  568. #pragma segment DlgRes
  569.  
  570. pascal TView* TDialogView::GetDialogView(void) // override 
  571. {
  572.     return this;
  573. }
  574.  
  575. //--------------------------------------------------------------------------------------------------
  576. #pragma segment MAOpen
  577.  
  578. pascal void TDialogView::DoOpen(void)
  579. {
  580. }
  581.  
  582. //--------------------------------------------------------------------------------------------------
  583. #pragma segment MAOpen
  584.  
  585. pascal void TDialogView::Open(void) // override 
  586.  
  587.     {
  588.     fDismisser = kNoIdentifier;
  589.     DoOpen();
  590.     inherited::Open();
  591.     }
  592.  
  593. //--------------------------------------------------------------------------------------------------
  594. #pragma segment DlgRes
  595.  
  596. pascal IDType TDialogView::PoseModally(void)
  597. {
  598.     TWindow*        itsWindow;
  599.  
  600.     itsWindow = this->GetWindow();
  601.     if (itsWindow != NULL)
  602.     {
  603.         itsWindow->PoseModally();
  604.         return fDismisser;
  605.     }    
  606.     else
  607.         return kNoIdentifier;
  608. }
  609.  
  610. //--------------------------------------------------------------------------------------------------
  611. #pragma segment DlgRes
  612.  
  613. pascal void TDialogView::SelectEditText(const IDType itsIdentifier,
  614.                                          Boolean selectChars)
  615. {
  616.     TView*        aSubView;
  617.     
  618.     aSubView = FindSubView(itsIdentifier);
  619.     if ((aSubView != NULL) && aSubView->IsMemberClass(GetClassIDFromName("TEditText")) )
  620.         DoSelectEditText((TEditText*) aSubView, selectChars);
  621. }
  622.  
  623. //--------------------------------------------------------------------------------------------------
  624. #pragma segment DlgRes
  625.  
  626. pascal void TDialogView::SurveyEditText(TEditText* first, 
  627.                                         TEditText* last, 
  628.                                         TEditText* next, 
  629.                                         TEditText* previous)
  630. /*RCR Would like to remove this method entirely
  631.  
  632.  
  633.     pascal void Survey(TEditText theEditText)
  634.  
  635.         {
  636.         if (theEditText.IsEnabled && theEditText->IsShown())
  637.             {
  638.             if (first == NULL)
  639.                 first = theEditText;
  640.             last = theEditText;
  641. //RCR        if (theEditText == this->GetCurrentEditText())
  642.                 foundCurrent = TRUE
  643.             else if (foundCurrent && (next == NULL))
  644.                 next = theEditText;
  645.             if (!foundCurrent)
  646.                 previous = theEditText;
  647.             }
  648.         }
  649. */
  650.     {
  651. /*    Boolean        foundCurrent;
  652.  
  653.     foundCurrent = False;
  654.     next = NULL;
  655.     previous = NULL;
  656.     first = NULL;
  657.     last = NULL;
  658.     EachEditText(Survey);
  659.     if (next == NULL)
  660.         next = first;
  661.     if (previous == NULL)
  662.         previous = last;
  663. */    }
  664.  
  665. //--------------------------------------------------------------------------------------------------
  666. #pragma segment DlgFields
  667.  
  668. pascal void TDialogView::Fields(TObject* obj) // override 
  669. {
  670.     obj->DoToField("TDialogView", NULL, bClass);
  671.     obj->DoToField("fDefaultItem", &fDefaultItem, bIDType);
  672.     obj->DoToField("fCancelItem", &fCancelItem, bIDType);
  673.     obj->DoToField("fDismisser", &fDismisser, bIDType);
  674.  
  675.     inherited::Fields(obj);
  676. }
  677.  
  678. //--------------------------------------------------------------------------------------------------
  679. #pragma segment DlgOpen
  680.  
  681. pascal void TButton::Initialize(void) // override 
  682. {
  683.  
  684.     inherited::Initialize();
  685.  
  686.     fDefChoice = mButtonHit;
  687. }
  688.  
  689. //--------------------------------------------------------------------------------------------------
  690. #pragma segment DlgOpen
  691.  
  692. pascal void TButton::IButton(TView* itsSuperView,
  693.                                const VPoint& itsLocation, 
  694.                              const VPoint& itsSize,
  695.                              SizeDeterminer itsHSizeDet, 
  696.                              SizeDeterminer itsVSizeDet,
  697.                                const Str255& itsLabel)
  698. {
  699.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 0,
  700.             ((pushButProc) |useWFont));
  701. }
  702.  
  703. //--------------------------------------------------------------------------------------------------
  704. #pragma segment DlgOpen
  705.  
  706. pascal void TButton::IRes(TDocument* ,
  707.                              TView* itsSuperView,
  708.                                Ptr& itsParams) // override 
  709.  
  710. {
  711.     VRect        itsArea;
  712.     
  713.     inherited::IRes(NULL, itsSuperView, itsParams);
  714.  
  715.     this->ControlArea(itsArea);
  716.     CreateCMgrControl(itsArea, ((ButtonTemplatePtr) itsParams)->itsLabel, 0, 0, 0, ((pushButProc) |useWFont));
  717.  
  718.     OffsetPtrWStr(itsParams, sizeof(ButtonTemplate));
  719. }
  720.  
  721. //--------------------------------------------------------------------------------------------------
  722. #pragma segment DlgRes
  723.  
  724. pascal TObject* TButton::Clone(void) // override 
  725. {
  726.     TButton*        aClonedButton;
  727.  
  728.     
  729.     aClonedButton = (TButton*)(inherited::Clone());
  730.     
  731.     return aClonedButton;
  732. }
  733.  
  734. //--------------------------------------------------------------------------------------------------
  735. #pragma segment MAWriteRes
  736.  
  737. pascal void TButton::WRes(ViewRsrcHandle theResource,
  738.                              Ptr& itsParams) // override 
  739. {
  740.     Str255                theLabel;
  741.  
  742.     inherited::WRes(theResource, itsParams);
  743.  
  744.     this->GetText(theLabel);
  745.  
  746.     ButtonTemplate&    templateData =
  747.         (ButtonTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(ButtonTemplate),
  748.                                              theLabel.Length()));
  749.  
  750.     // templateData.itsLabel = theLabel; 
  751.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  752. }
  753.  
  754. //--------------------------------------------------------------------------------------------------
  755. #pragma segment MAWriteRes
  756.  
  757. pascal void TButton::WriteRes(ViewRsrcHandle theResource,
  758.                                  Ptr& itsParams) // override 
  759.  
  760.     {
  761.     gWResSignature = 'butn'; gWResType = "TButton";
  762.     WRes(theResource, itsParams);
  763.     }
  764.  
  765. //--------------------------------------------------------------------------------------------------
  766. #pragma segment DlgRes
  767.  
  768. pascal void TButton::HandleEvent(EvtNumber eventNumber,
  769.                                 TEvtHandler* source,
  770.                                 TEvent* event) // override 
  771.  
  772. {
  773.     if ( (eventNumber == mButtonHit) && (source != this) && this->IsEnabled() )
  774.         this->Flash();
  775.     inherited::HandleEvent(eventNumber,source,event);
  776. }
  777.  
  778. //--------------------------------------------------------------------------------------------------
  779. #pragma segment DlgFields
  780.  
  781. pascal void TButton::Fields(TObject* obj) // override 
  782. {
  783.     obj->DoToField("TButton", NULL, bClass);
  784.  
  785.     inherited::Fields(obj);
  786. }
  787.  
  788. //--------------------------------------------------------------------------------------------------
  789. #pragma segment DlgOpen
  790.  
  791. pascal void TCheckBox::Initialize(void) // override 
  792. {
  793.     inherited::Initialize();
  794.  
  795.     fDefChoice = mCheckBoxHit;
  796. }
  797.  
  798. //--------------------------------------------------------------------------------------------------
  799. #pragma segment DlgOpen
  800.  
  801. pascal void TCheckBox::ICheckBox(TView* itsSuperView,
  802.                                    const VPoint& itsLocation, 
  803.                                  const VPoint& itsSize,
  804.                                    SizeDeterminer itsHSizeDet,
  805.                                  SizeDeterminer itsVSizeDet,
  806.                                    const Str255& itsLabel,
  807.                                    Boolean isTurnedOn)
  808.  
  809. {
  810.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1,
  811.             ((checkBoxProc) |useWFont));
  812.     this->SetState(isTurnedOn, kDontRedraw);
  813. }
  814.  
  815. //--------------------------------------------------------------------------------------------------
  816. #pragma segment DlgOpen
  817.  
  818. pascal void TCheckBox::IRes(TDocument* /* itsDocument */,
  819.                              TView*        itsSuperView,
  820.                              Ptr& itsParams) // override 
  821.  
  822. {
  823.     VRect        itsArea;
  824.  
  825.     inherited::IRes(NULL, itsSuperView, itsParams);
  826.  
  827.     ControlArea(itsArea);
  828.     CreateCMgrControl(itsArea, ((CheckBoxTemplatePtr) itsParams)->itsLabel, (long)(this->IsOn()), 0, 1, ((checkBoxProc) |useWFont));
  829.  
  830.     OffsetPtrWStr(itsParams, sizeof(CheckBoxTemplate));
  831. }
  832.  
  833. //--------------------------------------------------------------------------------------------------
  834. #pragma segment DlgRes
  835.  
  836. pascal TObject* TCheckBox::Clone(void) // override 
  837. {
  838.     TCheckBox*    aClonedCheckBox;
  839.  
  840.     aClonedCheckBox = (TCheckBox*)(inherited::Clone());
  841.         
  842.     return aClonedCheckBox;
  843. }
  844.  
  845. //--------------------------------------------------------------------------------------------------
  846. #pragma segment MAWriteRes
  847.  
  848. pascal void TCheckBox::WRes(ViewRsrcHandle theResource,
  849.                              Ptr& itsParams) // override 
  850. {
  851.     Str255        theLabel;
  852.  
  853.     inherited::WRes(theResource, itsParams);
  854.  
  855.     this->GetText(theLabel);
  856.  
  857.     CheckBoxTemplate&    templateData =
  858.         (CheckBoxTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(CheckBoxTemplate),
  859.                                                theLabel.Length()));
  860.  
  861.     templateData.isOn = this->IsOn();
  862.     // templateData.itsLabel = theLabel; 
  863.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  864. }
  865.  
  866. //--------------------------------------------------------------------------------------------------
  867. #pragma segment MAWriteRes
  868.  
  869. pascal void TCheckBox::WriteRes(ViewRsrcHandle theResource,
  870.                                  Ptr& itsParams) // override 
  871. {
  872.     gWResSignature = 'chkb'; gWResType = "TCheckBox";
  873.     WRes(theResource, itsParams);
  874. }
  875.  
  876. //--------------------------------------------------------------------------------------------------
  877. #pragma segment DlgRes
  878.  
  879. pascal void TCheckBox::HandleEvent(EvtNumber eventNumber,
  880.                                    TEvtHandler*    source,
  881.                                    TEvent* event) // override 
  882.  
  883. {
  884.     if (eventNumber == mCheckBoxHit)
  885.         this->Toggle(kRedraw);
  886.     inherited::HandleEvent(eventNumber,source,event);
  887. }
  888.  
  889. //--------------------------------------------------------------------------------------------------
  890. #pragma segment DlgRes
  891.  
  892. pascal Boolean TCheckBox::IsOn(void)
  893. {
  894.     return (this->GetLongVal() != 0);
  895. }
  896.  
  897. //--------------------------------------------------------------------------------------------------
  898. #pragma segment DlgRes
  899.  
  900. pascal void TCheckBox::SetState(Boolean state, 
  901.                                 Boolean redraw)
  902. {
  903.     this->SetLongVal((long) state, redraw);
  904. }
  905.  
  906. //--------------------------------------------------------------------------------------------------
  907. #pragma segment DlgRes
  908.  
  909. pascal void TCheckBox::Toggle(Boolean redraw)
  910.  
  911. {
  912.     this->SetLongVal( (long) (! this->IsOn()), redraw);
  913. }
  914.  
  915. //--------------------------------------------------------------------------------------------------
  916. #pragma segment DlgRes
  917.  
  918. pascal void TCheckBox::ToggleIf(Boolean matchState, 
  919.                                 Boolean redraw)
  920. {
  921.     if (this->IsOn() == matchState)
  922.         this->SetLongVal( (long) (! this->IsOn()), redraw);
  923. }
  924.  
  925. //--------------------------------------------------------------------------------------------------
  926. #pragma segment DlgFields
  927.  
  928. pascal void TCheckBox::Fields(TObject* obj) // override 
  929. {
  930.     obj->DoToField("TCheckBox", NULL, bClass);
  931.  
  932.     inherited::Fields(obj);
  933. }
  934.  
  935. //--------------------------------------------------------------------------------------------------
  936. #pragma segment DlgOpen
  937.  
  938. pascal void TRadio::Initialize(void) // override 
  939. {
  940.     inherited::Initialize();
  941.  
  942.     fDefChoice = mRadioHit;
  943. }
  944.  
  945. //--------------------------------------------------------------------------------------------------
  946. #pragma segment DlgOpen
  947.  
  948. pascal void TRadio::IRadio(TView* itsSuperView,
  949.                            const VPoint& itsLocation,
  950.                            const VPoint& itsSize,
  951.                            SizeDeterminer itsHSizeDet,
  952.                            SizeDeterminer itsVSizeDet,
  953.                            const Str255& itsLabel,
  954.                            Boolean isTurnedOn)
  955.  
  956. {
  957.     this->ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1,
  958.             ((radioButProc) |useWFont));
  959.     this->SetState(isTurnedOn, kDontRedraw);
  960. }
  961.  
  962. //--------------------------------------------------------------------------------------------------
  963. #pragma segment DlgOpen
  964.  
  965. pascal void TRadio::IRes(TDocument* ,
  966.                            TView*    itsSuperView,
  967.                            Ptr& itsParams) // override 
  968.  
  969. {
  970.     VRect        itsArea;
  971.  
  972.     inherited::IRes(NULL, itsSuperView, itsParams);
  973.  
  974.     this->ControlArea(itsArea);
  975.     this->CreateCMgrControl(itsArea, ((RadioTemplatePtr) itsParams)->itsLabel, (long) (this->IsOn()), 0, 1, ((radioButProc) |useWFont));
  976.     OffsetPtrWStr(itsParams, sizeof(RadioTemplate));
  977. }
  978.  
  979. //--------------------------------------------------------------------------------------------------
  980. #pragma segment DlgRes
  981.  
  982. pascal TObject* TRadio::Clone(void) // override 
  983. {
  984.     TRadio*        aClonedRadio;
  985.  
  986.     aClonedRadio = (TRadio*) (inherited::Clone());
  987.         
  988.     return aClonedRadio;
  989. }
  990.  
  991. //--------------------------------------------------------------------------------------------------
  992. #pragma segment MAWriteRes
  993.  
  994. pascal void TRadio::WRes(ViewRsrcHandle theResource,
  995.                            Ptr& itsParams) // override 
  996.  
  997. {
  998.     Str255        theLabel;
  999.  
  1000.     inherited::WRes(theResource, itsParams);
  1001.  
  1002.     this->GetText(theLabel);
  1003.  
  1004.     RadioTemplate&    templateData =
  1005.         (RadioTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(RadioTemplate),
  1006.                                             theLabel.Length()));
  1007.  
  1008.     templateData.isOn = this->IsOn();
  1009.     // templateData.itsLabel = theLabel; 
  1010.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  1011. }
  1012.  
  1013. //--------------------------------------------------------------------------------------------------
  1014. #pragma segment MAWriteRes
  1015.  
  1016. pascal void TRadio::WriteRes(ViewRsrcHandle theResource,
  1017.                               Ptr& itsParams) // override 
  1018. {
  1019.     gWResSignature = 'radb'; gWResType = "TRadio";
  1020.     this->WRes(theResource, itsParams);
  1021. }
  1022.  
  1023. //--------------------------------------------------------------------------------------------------
  1024. #pragma segment DlgRes
  1025.  
  1026. pascal void TRadio::HandleEvent(EvtNumber eventNumber,
  1027.                                 TEvtHandler* source,
  1028.                                 TEvent* event) // override 
  1029.  
  1030. {
  1031.     if ((eventNumber == mRadioHit) && !this->IsOn())
  1032.         this->Toggle(kRedraw);
  1033.     inherited::HandleEvent(eventNumber,source,event);
  1034. }
  1035.  
  1036. //--------------------------------------------------------------------------------------------------
  1037. #pragma segment DlgRes
  1038.  
  1039. pascal Boolean TRadio::IsOn(void)
  1040. {
  1041.     return (this->GetLongVal() != 0);
  1042. }
  1043.  
  1044. //--------------------------------------------------------------------------------------------------
  1045. #pragma segment DlgRes
  1046.  
  1047. pascal void TRadio::SetState(Boolean state, 
  1048.                              Boolean redraw)
  1049. {
  1050.     this->SetLongVal( (long)(state), redraw);
  1051. }
  1052.  
  1053. //--------------------------------------------------------------------------------------------------
  1054. #pragma segment DlgRes
  1055.  
  1056. pascal void TRadio::Toggle(Boolean redraw)
  1057. {
  1058.     this->SetLongVal((long) (! this->IsOn()), redraw);
  1059. }
  1060.  
  1061. //--------------------------------------------------------------------------------------------------
  1062. #pragma segment DlgRes
  1063.  
  1064. pascal void TRadio::ToggleIf(Boolean matchState, 
  1065.                              Boolean redraw)
  1066. {
  1067.     if (this->IsOn() == matchState)
  1068.         this->SetLongVal((long) (! this->IsOn()), redraw);
  1069. }
  1070.  
  1071. //--------------------------------------------------------------------------------------------------
  1072. #pragma segment DlgFields
  1073.  
  1074. pascal void TRadio::Fields(TObject* obj) // override 
  1075. {
  1076.     obj->DoToField("TRadio", NULL, bClass);
  1077.  
  1078.     inherited::Fields(obj);
  1079. }
  1080.  
  1081. //--------------------------------------------------------------------------------------------------
  1082. #pragma segment DlgOpen
  1083.  
  1084. pascal void TCluster::Initialize(void) // override 
  1085.  
  1086.     {
  1087.     inherited::Initialize();
  1088.  
  1089.     fDataHandle = NULL;
  1090.     fRsrcID = kNoResource;
  1091.     fIndex = 0;                                        // ??? Is there a constant for this 
  1092.  
  1093.     fDefChoice = mClusterHit;
  1094.     }
  1095.  
  1096. //--------------------------------------------------------------------------------------------------
  1097. #pragma segment DlgOpen
  1098.  
  1099. pascal void TCluster::ICluster(TView* itsSuperView,
  1100.                                const VPoint& itsLocation, 
  1101.                                const VPoint& itsSize,
  1102.                                SizeDeterminer itsHSizeDet,
  1103.                                SizeDeterminer itsVSizeDet,
  1104.                                short itsRsrcID, 
  1105.                                short itsIndex)
  1106.  
  1107.  
  1108. {
  1109.     Str255        aString;
  1110.     FailInfo        fi;
  1111.  
  1112.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1113.     fRsrcID = itsRsrcID;
  1114.     fIndex = itsIndex;
  1115.     if (fRsrcID != kNoResource)
  1116.     {
  1117.         if (! fi.CatchFailure() )
  1118.         {
  1119.             GetIndString(aString, fRsrcID, fIndex);
  1120.             FailResError();
  1121.             fi.Success();
  1122.         }
  1123.         else
  1124.         {
  1125.             this->Free();
  1126.             fi.ReSignal();
  1127.         }
  1128.         
  1129.         this->SetLabel(aString, kDontRedraw);
  1130.     }
  1131.     this->SetEnable(False);                                    // Default is not to enable hit testing 
  1132. }
  1133.  
  1134. //--------------------------------------------------------------------------------------------------
  1135. #pragma segment DlgOpen
  1136.  
  1137. pascal void TCluster::IRes(TDocument* ,
  1138.                            TView* itsSuperView,
  1139.                            Ptr& itsParams) // override 
  1140.  
  1141. {
  1142.     inherited::IRes(NULL, itsSuperView, itsParams);
  1143.  
  1144.     this->SetLabel(((ClusterTemplatePtr) itsParams)->itsLabel, kDontRedraw);
  1145.  
  1146.     OffsetPtrWStr(itsParams, sizeof(ClusterTemplate));
  1147. }
  1148.  
  1149. //--------------------------------------------------------------------------------------------------
  1150. #pragma segment DlgRes
  1151.  
  1152. pascal TObject* TCluster::Clone(void) // override 
  1153. {
  1154.     TCluster*    aClonedCluster;
  1155.     Str255        theLabel;
  1156.  
  1157.     
  1158.     aClonedCluster = (TCluster*) (inherited::Clone());
  1159.     
  1160.     aClonedCluster->fDataHandle = NULL;
  1161.     this->GetLabel(theLabel);
  1162.     aClonedCluster->SetLabel(theLabel, kDontRedraw);
  1163.  
  1164.     return aClonedCluster;
  1165.     }
  1166.  
  1167. //--------------------------------------------------------------------------------------------------
  1168. #pragma segment MAWriteRes
  1169.  
  1170. pascal void TCluster::WRes(ViewRsrcHandle theResource,
  1171.                            Ptr& itsParams) // override 
  1172.  
  1173. {
  1174.     Str255        theLabel;
  1175.     
  1176.     inherited::WRes(theResource, itsParams);
  1177.  
  1178.     this->GetLabel(theLabel);
  1179.  
  1180.     ClusterTemplate&    templateData =
  1181.         (ClusterTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(ClusterTemplate),
  1182.                                               theLabel.Length()));
  1183.  
  1184.     // templateData.itsLabel = theLabel; 
  1185.     CopyStr255(theLabel, PRStr(templateData.itsLabel));
  1186. }
  1187.  
  1188. //--------------------------------------------------------------------------------------------------
  1189. #pragma segment MAWriteRes
  1190.  
  1191. pascal void TCluster::WriteRes(ViewRsrcHandle theResource,
  1192.                                Ptr& itsParams) // override 
  1193.  
  1194. {
  1195.     gWResSignature = 'clus'; gWResType = "TCluster";
  1196.     this->WRes(theResource, itsParams);
  1197. }
  1198.  
  1199. //--------------------------------------------------------------------------------------------------
  1200. #pragma segment DlgClose
  1201.  
  1202. pascal void TCluster::Free(void) // override 
  1203. {
  1204.     this->ReleaseLabel();
  1205.     inherited::Free();
  1206. }
  1207.  
  1208. //--------------------------------------------------------------------------------------------------
  1209. #pragma segment DlgRes
  1210.  
  1211. //RCR Iteration object for ResetRadios
  1212.  
  1213. class CResetRadios
  1214. {
  1215.     const TEvtHandler*&        fSource;
  1216. public:
  1217.     // Constructor
  1218.     CResetRadios(const TEvtHandler*& source):
  1219.         fSource (source) {};
  1220.     
  1221.     pascal void ResetRadios(TView* aView);
  1222. };
  1223.  
  1224. pascal void CResetRadios::ResetRadios(TView* aView)
  1225.  
  1226. {
  1227.     if (aView->IsMemberClass(GetClassIDFromName("TRadio"))             // If the subview is a TRadio, and… 
  1228.        && (aView != fSource))                                        // …it's not the calling radio… 
  1229.         ((TRadio*) aView)->SetState(False, kRedraw);                 // …set it off and redraw it 
  1230. };
  1231.  
  1232. pascal void TCluster::HandleEvent(EvtNumber eventNumber,
  1233.                                   TEvtHandler*        source,
  1234.                                   TEvent* event) // override 
  1235.  
  1236.  
  1237. {
  1238.     if ((eventNumber == mRadioHit) &&                        /* If we got this far, a radio's changed
  1239.                                                          state */
  1240.        (((TView*) source)->fSuperView == this))            // Only worry about it if it's our subview! 
  1241.     {
  1242.         CResetRadios aCResetRadios(source);
  1243.         
  1244.         EachSubView((DoToViewType) &CResetRadios::ResetRadios,&aCResetRadios);    // Reset everybody except the calling radio 
  1245.     }
  1246.     inherited::HandleEvent(eventNumber,source,event);
  1247. }
  1248.  
  1249. //--------------------------------------------------------------------------------------------------
  1250. #pragma segment DlgRes
  1251.  
  1252. pascal void TCluster::Draw(const VRect& area) // override 
  1253. {
  1254.     short        theFontHeight;
  1255.     VCoordinate    theFrameTop;
  1256.     VRect        theFrame;
  1257.     Rect        theQDFrame;
  1258.     RGBColor    oldColor;
  1259.     TextStyle    aTextStyle;
  1260.     FontInfo    theFontInfo;
  1261.  
  1262.     if (fDataHandle != NULL)
  1263.     {
  1264.         PenNormal();                                        // Normalcy in most things 
  1265.  
  1266.         PenSize(fPenSize.h, fPenSize.v);                // PenSize(2, 2); 
  1267.  
  1268.         GetIfColor(oldColor);                            // Save the original pen color 
  1269.         aTextStyle = fTextStyle;
  1270.         GetTextStyleFontInfo(aTextStyle, theFontInfo, theFontHeight);
  1271.         this->ControlArea(theFrame);                            // Get the control's extent 
  1272.         theFrameTop = theFrame.top + ((theFontHeight) >> 1);
  1273.  
  1274.         InsetVRect(theFrame, fPenSize.h + 1, fPenSize.v + 1);    // Inset the frame a little 
  1275.  
  1276.         theFrame.top = theFrameTop;                    // Bump top so it cuts label in half 
  1277.  
  1278.         this->ViewToQDRect(theFrame, theQDFrame);
  1279.         FrameRect(theQDFrame);                            // Draw the frame 
  1280.         this->DrawLabel(area);                                // Draw the label 
  1281.  
  1282.         SetIfColor(oldColor);
  1283.     }
  1284.     inherited::Draw(area);                                // Let parents have a chance to draw too 
  1285. }
  1286.  
  1287. //--------------------------------------------------------------------------------------------------
  1288. #pragma segment DlgRes
  1289.  
  1290. pascal void TCluster::DrawLabel(const VRect& area)
  1291. {
  1292.     TextStyle        aTextStyle;
  1293.     Str255        theText;
  1294.     VRect        labelRect;
  1295.     Rect        labelQDRect;
  1296.     VRect        dstRect;
  1297.     FontInfo        theFontInfo;
  1298.  
  1299.     
  1300.     aTextStyle = fTextStyle;
  1301.     SetPortTextStyle(aTextStyle);                        // Install the object's TextStyle 
  1302.  
  1303.     this->GetLabel(theText);                                    // retrieve the label 
  1304.  
  1305.     MAReplaceText(theText);
  1306.  
  1307.     SetVRect(labelRect, 16, 0, StringWidth(theText) + 8 + 16, MAGetFontInfo(theFontInfo));
  1308.     if (SectVRect(area, labelRect, dstRect))
  1309.     {
  1310.         this->ViewToQDRect(labelRect, labelQDRect);
  1311.         MATextBox(Ptr(((long)&theText) + 1), theText.Length(), labelQDRect, teCenter, kNoAutoWrap,
  1312.                   NULL, kEraseFirst, kNoSpaceForCaret);
  1313.     }
  1314. }
  1315.  
  1316. //--------------------------------------------------------------------------------------------------
  1317. #pragma segment DlgNonRes
  1318. typedef Str255*    RCRStringPtr;
  1319. typedef RCRStringPtr*    RCRStringHandle;
  1320.  
  1321. pascal void TCluster::GetLabel(Str255& theLabel)
  1322. {
  1323.     if (fDataHandle != NULL)
  1324.         CopyStr255( (**((RCRStringHandle) fDataHandle)), (Ptr)&theLabel);
  1325.     else
  1326.         theLabel = "";
  1327. }
  1328.  
  1329. //--------------------------------------------------------------------------------------------------
  1330. #pragma segment DlgNonRes
  1331.  
  1332. pascal void TCluster::ReleaseLabel(void)
  1333. {
  1334.     fDataHandle = (StringHandle) DisposeIfHandle( (Handle) fDataHandle);
  1335.  
  1336.     fRsrcID = kNoResource;
  1337. }
  1338.  
  1339. //--------------------------------------------------------------------------------------------------
  1340. #pragma segment DlgRes
  1341.  
  1342. pascal Boolean FindRadio(TView* aView,void* /* staticLink */)
  1343. {
  1344.     return ( aView->IsMemberClass(GetClassIDFromName("TRadio")) && ((TRadio*) aView)->IsOn() )  ;
  1345. }
  1346.  
  1347. pascal IDType TCluster::ReportCurrent(void)
  1348. {
  1349.     TView*        rView;
  1350.  
  1351.     rView = this->FirstSubViewThat(FindRadio,this);
  1352.     if (rView != NULL)
  1353.         return (rView->fIdentifier);
  1354.     else
  1355.         return kNoIdentifier;
  1356. }
  1357.  
  1358. //--------------------------------------------------------------------------------------------------
  1359. #pragma segment DlgNonRes
  1360.  
  1361. pascal void TCluster::SetLabel(const Str255& theLabel,
  1362.                                Boolean redraw)
  1363.  
  1364. {
  1365.     this->ReleaseLabel();
  1366.     if (theLabel != "")
  1367.     {
  1368.         fDataHandle = NewString(theLabel);
  1369.         if (MemError() != noErr)
  1370.             fDataHandle = NULL;
  1371.     }
  1372.     if (redraw)
  1373.         this->ForceRedraw();
  1374. }
  1375.  
  1376. //--------------------------------------------------------------------------------------------------
  1377. #pragma segment DlgFields
  1378.  
  1379. pascal void TCluster::Fields(TObject* obj) // override 
  1380. {
  1381.     Str255        aString;
  1382.  
  1383.     obj->DoToField("TCluster", NULL, bClass);
  1384.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  1385.     obj->DoToField("fIndex", &fIndex, bInteger);
  1386.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  1387.     if (fDataHandle != NULL)
  1388.     {
  1389.         aString = (**((RCRStringHandle) fDataHandle));
  1390.         obj->DoToField("**fDataHandle", &aString, bString);
  1391.     }
  1392.  
  1393.     inherited::Fields(obj);
  1394. }
  1395.  
  1396. //--------------------------------------------------------------------------------------------------
  1397. #pragma segment DlgOpen
  1398.  
  1399. pascal void TIcon::Initialize(void) // override 
  1400.  
  1401.     {
  1402.     inherited::Initialize();
  1403.  
  1404.     fDataHandle = NULL;
  1405.     fIsColor = kPreferColor;
  1406.     fPreferColor = kPreferColor;
  1407.     fRsrcID = kNoResource;
  1408.  
  1409.     fDefChoice = mIconHit;
  1410.     }
  1411.  
  1412. //--------------------------------------------------------------------------------------------------
  1413. #pragma segment DlgOpen
  1414.  
  1415. pascal void TIcon::IIcon(TView* itsSuperView,
  1416.                            const VPoint& itsLocation, 
  1417.                          const VPoint& itsSize,
  1418.                            SizeDeterminer itsHSizeDet, 
  1419.                          SizeDeterminer itsVSizeDet,
  1420.                            short itsRsrcID,
  1421.                            Boolean preferColor)
  1422.  
  1423. {
  1424.     FailInfo        fi;
  1425.     Handle        itsRsrcHandle;
  1426.     SignedByte        savedState;
  1427.  
  1428.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1429.     fPreferColor = preferColor;
  1430.     fIsColor = preferColor;
  1431.     fRsrcID = itsRsrcID;
  1432.     if (fRsrcID != kNoResource)
  1433.     {
  1434.         if (! fi.CatchFailure() )
  1435.         {
  1436.             if ((fPreferColor) &&  (qNeedsColorQD || gConfiguration.hasColorQD))
  1437.             {
  1438.                 // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die 
  1439.                 itsRsrcHandle = GetResource('cicn', fRsrcID);
  1440.                 if (itsRsrcHandle != NULL)
  1441.                 {
  1442.                     savedState = HGetState(itsRsrcHandle);
  1443.                     HNoPurge(itsRsrcHandle);
  1444.                 }
  1445.                 
  1446.                 fDataHandle = Handle(GetCIcon(fRsrcID));
  1447.             
  1448.                 // restore the state of the 'cicn' resource 
  1449.                 if (itsRsrcHandle != NULL)
  1450.                     HSetState(itsRsrcHandle, savedState);
  1451.             }
  1452.             if (fDataHandle == NULL)
  1453.             {
  1454.                 fDataHandle = GetIcon(fRsrcID);
  1455.                 if (fDataHandle != NULL)
  1456.                     fIsColor = !kPreferColor;            // Either can't or won't 
  1457.             }
  1458.             FailResError();
  1459.             fi.Success();
  1460.         }
  1461.         else
  1462.         {
  1463.             this->Free();
  1464.             fi.ReSignal();
  1465.         }
  1466.     }
  1467.     this->SetEnable(False);                                    // Default is to not enable hit testing     }
  1468. }
  1469.  
  1470. //--------------------------------------------------------------------------------------------------
  1471. #pragma segment DlgOpen
  1472.  
  1473. pascal void TIcon::IRes(TDocument* ,
  1474.                          TView*        itsSuperView,
  1475.                         Ptr& itsParams) // override 
  1476. {
  1477.     FailInfo        fi;
  1478.     Handle            itsRsrcHandle;
  1479.     SignedByte        savedState;
  1480.  
  1481.     fDataHandle = NULL;
  1482.     inherited::IRes(NULL, itsSuperView, itsParams);
  1483.  
  1484.     IconTemplate& templateData = (IconTemplate&) *itsParams;
  1485.  
  1486.     fPreferColor = templateData.preferColor;
  1487.     fIsColor = templateData.preferColor;
  1488.     fRsrcID = templateData.rsrcID;
  1489.  
  1490.     if (fRsrcID != kNoResource)
  1491.     {
  1492.         if (! fi.CatchFailure() )
  1493.         {
  1494.             if ( (fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
  1495.             {
  1496.                 // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die 
  1497.                 itsRsrcHandle = GetResource('cicn', fRsrcID);
  1498.                 if (itsRsrcHandle != NULL)
  1499.                     {
  1500.                     savedState = HGetState(itsRsrcHandle);
  1501.                     HNoPurge(itsRsrcHandle);
  1502.                     }
  1503.                 
  1504.                 fDataHandle = Handle(GetCIcon(fRsrcID));
  1505.             
  1506.                 // restore the state of the 'cicn' resource 
  1507.                 if (itsRsrcHandle != NULL)
  1508.                     HSetState(itsRsrcHandle, savedState);
  1509.             }
  1510.             if (fDataHandle == NULL)
  1511.             {
  1512.                 fDataHandle = GetIcon(fRsrcID);
  1513.                 if (fDataHandle != NULL)
  1514.                     fIsColor = !kPreferColor;        // Either can't or won't 
  1515.             }
  1516.             // Don't die because resource not found - just return NULL handle 
  1517.             FailResError();
  1518.             fi.Success();
  1519.         }
  1520.         else
  1521.         {
  1522.             this->Free();
  1523.             fi.ReSignal();
  1524.         }
  1525.     }
  1526.  
  1527.     OffsetPtr(itsParams, sizeof(IconTemplate));
  1528. }
  1529.  
  1530. //--------------------------------------------------------------------------------------------------
  1531. #pragma segment DlgRes
  1532.  
  1533. pascal TObject* TIcon::Clone(void) // override 
  1534. {
  1535.     TIcon*        aClonedIcon;
  1536.     Handle        aHandle;
  1537.     OSErr        err;
  1538.     Handle        itsRsrcHandle;
  1539.     SignedByte        savedState;
  1540.  
  1541.     
  1542.     aClonedIcon = (TIcon*) (inherited::Clone());
  1543.     aClonedIcon->fDataHandle = NULL;
  1544.     
  1545.     if (fDataHandle != NULL)
  1546.     {
  1547.         if (fIsColor)
  1548.         {
  1549.             // make the 'cicn' resource non-purgeable, so the Toolbox doesn't die 
  1550.             itsRsrcHandle = GetResource('cicn', fRsrcID);
  1551.             if (itsRsrcHandle != NULL)
  1552.                 {
  1553.                 savedState = HGetState(itsRsrcHandle);
  1554.                 HNoPurge(itsRsrcHandle);
  1555.                 }
  1556.                 
  1557.             aClonedIcon->fDataHandle = Handle(GetCIcon(fRsrcID));
  1558.             
  1559.             // restore the state of the 'cicn' resource 
  1560.             if (itsRsrcHandle != NULL)
  1561.                 HSetState(itsRsrcHandle, savedState);
  1562.         }        
  1563.         else
  1564.         {
  1565.             aHandle = fDataHandle;
  1566.             err = HandToHand(aHandle);
  1567.             if (err != noErr)
  1568.                 FailNIL(aHandle);
  1569.             aClonedIcon->fDataHandle = aHandle;
  1570.         }
  1571.     }
  1572.     return aClonedIcon;
  1573. }
  1574.  
  1575. //--------------------------------------------------------------------------------------------------
  1576. #pragma segment MAWriteRes
  1577.  
  1578. pascal void TIcon::WRes(ViewRsrcHandle theResource,
  1579.                          Ptr& itsParams) // override 
  1580. {
  1581.     inherited::WRes(theResource, itsParams);
  1582.  
  1583.     IconTemplate&    templateData =
  1584.         (IconTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(IconTemplate)));
  1585.  
  1586.     templateData.preferColor = fPreferColor;
  1587. #if qDebug
  1588.         if (fRsrcID == kNoResource)
  1589.             cout << "Tried to write TIcon with no resource ID.\n";
  1590. #endif
  1591.     templateData.rsrcID = fRsrcID;
  1592. }
  1593.  
  1594. //--------------------------------------------------------------------------------------------------
  1595. #pragma segment MAWriteRes
  1596.  
  1597. pascal void TIcon::WriteRes(ViewRsrcHandle theResource,
  1598.                          Ptr& itsParams) // override 
  1599. {
  1600.     gWResSignature = 'icon'; gWResType = "TIcon";
  1601.     this->WRes(theResource, itsParams);
  1602. }
  1603.  
  1604. //--------------------------------------------------------------------------------------------------
  1605. #pragma segment DlgClose
  1606.  
  1607. pascal void TIcon::Free(void) // override 
  1608. {
  1609.     this->ReleaseIcon();
  1610.  
  1611.     inherited::Free();
  1612. }
  1613.  
  1614. //--------------------------------------------------------------------------------------------------
  1615. #pragma segment DlgRes
  1616.  
  1617. pascal void TIcon::Draw(const VRect& area) // override 
  1618. {
  1619.     SignedByte        oldState;
  1620.     VRect        theRect;
  1621.     Rect        theQDRect;
  1622.     PixMap        aPixMap;
  1623.     BitMapPtr        aBitMapPtr;
  1624.     Rect        srcRect;
  1625.  
  1626.     
  1627.     if (fDataHandle != NULL)
  1628.     {
  1629.         if (IsAResource(fDataHandle))
  1630.             LoadResource(fDataHandle);
  1631.         if ((*fDataHandle) != NULL)                     // If there's room for the icon… 
  1632.         {
  1633.             PenNormal();                                    // NECESSARY? 
  1634.             ControlArea(theRect);
  1635.             ViewToQDRect(theRect, theQDRect);
  1636.             oldState = HGetState(fDataHandle);
  1637.             HNoPurge(fDataHandle);
  1638.             HLock(fDataHandle);
  1639.  
  1640.             if (fIsColor)
  1641.             {
  1642.  
  1643.                 // We can't use PlotCIcon here because it can't be written to a picture 
  1644.                 // and when WriteToDeskScrap is called, the icon is plotted on the 
  1645.                 // desktop rather than in the picture.  So instead, pick apart the color 
  1646.                 // icon handle and use copybits, ignoring the mask. 
  1647.  
  1648.                 aPixMap = (**((CIconHandle)  fDataHandle)).iconPMap;
  1649.                 HLock((**((CIconHandle) fDataHandle )).iconData);
  1650.                 aPixMap.baseAddr = *((**((CIconHandle) fDataHandle)).iconData);
  1651.                 srcRect = aPixMap.bounds;
  1652.                 aBitMapPtr = (BitMapPtr) &aPixMap;
  1653.                 CopyBits((*aBitMapPtr), qd.thePort->portBits, srcRect, theQDRect, srcCopy, NULL);
  1654.                 HUnlock((**((CIconHandle) fDataHandle )).iconData);
  1655.             }            
  1656.             else
  1657.                 PlotIcon(&theQDRect, fDataHandle);
  1658.  
  1659.             HSetState(fDataHandle, oldState);
  1660.         }
  1661.     }
  1662.  
  1663.     inherited::Draw(area);
  1664. }
  1665.  
  1666. //--------------------------------------------------------------------------------------------------
  1667. #pragma segment DlgNonRes
  1668.  
  1669. pascal void TIcon::ReleaseIcon(void)
  1670. {
  1671.     fRsrcID = kNoResource;
  1672.     if (fDataHandle != NULL)
  1673.     {
  1674.         if (fIsColor)
  1675.             DisposCIcon((CIconHandle) fDataHandle);
  1676.         else
  1677.             HPurge(fDataHandle);
  1678.         fDataHandle = NULL;
  1679.     }
  1680. }
  1681.  
  1682. //--------------------------------------------------------------------------------------------------
  1683. #pragma segment DlgNonRes
  1684.  
  1685. pascal void TIcon::SetIcon(Handle theIcon,
  1686.                            Boolean redraw)
  1687. {
  1688.     short        theID;
  1689.     ResType        theType;
  1690.     Str255        name;
  1691.  
  1692.     
  1693.     this->ReleaseIcon();
  1694.     if (GetHandleSize(theIcon) != 128)
  1695.         fPreferColor= TRUE;
  1696.     else
  1697.         fPreferColor= FALSE;
  1698.     fDataHandle = theIcon;
  1699.  
  1700.     // get the rsrc id 
  1701.     GetResInfo(theIcon, theID, theType, name);
  1702.     if (ResError() == noErr)
  1703.         fRsrcID = theID;
  1704.  
  1705.     if (redraw)
  1706.         this->ForceRedraw();
  1707. }
  1708.  
  1709. //--------------------------------------------------------------------------------------------------
  1710. #pragma segment DlgFields
  1711.  
  1712. pascal void TIcon::Fields(TObject* obj) // override 
  1713. {
  1714.     obj->DoToField("TIcon", NULL, bClass);
  1715.     obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
  1716.     obj->DoToField("fIsColor", &fIsColor, bBoolean);
  1717.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  1718.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  1719.  
  1720.     inherited::Fields(obj);
  1721. }
  1722.  
  1723. //--------------------------------------------------------------------------------------------------
  1724. #pragma segment DlgOpen
  1725. pascal void TSmallIcon::Initialize(void) // override 
  1726. {
  1727.      inherited::Initialize();
  1728.     fDataHandle = NULL;
  1729.     fRsrcID = kNoResource;
  1730.     fDefChoice = mSmallIconHit;
  1731.  }
  1732.     
  1733. //--------------------------------------------------------------------------------------------------
  1734. #pragma segment DlgOpen
  1735.  
  1736. pascal void TSmallIcon::ISmallIcon(TView* itsSuperView,
  1737.                                    const VPoint& itsLocation,
  1738.                                    const VPoint& itsSize,
  1739.                                    SizeDeterminer itsHSizeDet, 
  1740.                                    SizeDeterminer itsVSizeDet,
  1741.                                    short itsRsrcID)
  1742. {
  1743.     FailInfo        fi;
  1744.  
  1745.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1746.     fRsrcID = itsRsrcID;
  1747.     if (fRsrcID != kNoResource)
  1748.     {
  1749.         if (! fi.CatchFailure())
  1750.         {
  1751.             fDataHandle = GetResource('SICN', fRsrcID);
  1752.             FailResError();
  1753.             fi.Success();
  1754.         }
  1755.         else
  1756.         {
  1757.             this->Free();
  1758.             fi.ReSignal();
  1759.         }
  1760.     }
  1761.     this->SetEnable(False);                                    // Default is to not enable hit testing 
  1762. }
  1763.  
  1764. //--------------------------------------------------------------------------------------------------
  1765. #pragma segment DlgOpen
  1766.  
  1767. pascal void TSmallIcon::IRes(TDocument* ,
  1768.                                TView*    itsSuperView,
  1769.                                Ptr& itsParams) // override 
  1770. {
  1771.     const short    kReadOnlySICN        = 256;                        // resource ID of small slashed pencil icon 
  1772.     FailInfo        fi;
  1773.     
  1774.     inherited::IRes(NULL, itsSuperView, itsParams);
  1775.  
  1776.     //  fRsrcID = SmallIconTemplatePtr(itsParams)->rsrcID; 
  1777.     fRsrcID = kReadOnlySICN;                            // until MacApp 2.1.0.1 
  1778.     if (fRsrcID != kNoResource)
  1779.     {
  1780.         if (! fi.CatchFailure())
  1781.         {
  1782.             fDataHandle = GetResource('SICN', fRsrcID);
  1783.             FailResError();
  1784.             fi.Success();
  1785.         }
  1786.         else
  1787.         {
  1788.             this->Free();
  1789.             fi.ReSignal();
  1790.         }
  1791.     }
  1792.  
  1793.     //  OffsetPtr(itsParams, sizeof(SmallIconTemplate));    
  1794. }
  1795.  
  1796. //--------------------------------------------------------------------------------------------------
  1797. #pragma segment DlgRes
  1798.  
  1799. pascal TObject* TSmallIcon::Clone(void) // override 
  1800. {
  1801.     TSmallIcon*        aClonedSmallIcon;
  1802.     Handle        aHandle;
  1803.     OSErr        err;
  1804.  
  1805.     
  1806.     aClonedSmallIcon = (TSmallIcon*)(inherited::Clone());
  1807.  
  1808.     aHandle = aClonedSmallIcon->fDataHandle;
  1809.     if (aHandle != NULL)
  1810.     {
  1811.         err = HandToHand(aHandle);
  1812.         if (err != noErr)
  1813.             FailNIL(aHandle);
  1814.         aClonedSmallIcon->fDataHandle = aHandle;
  1815.     }
  1816.     
  1817.     return aClonedSmallIcon;
  1818. }
  1819.  
  1820. //--------------------------------------------------------------------------------------------------
  1821. #pragma segment MAWriteRes
  1822.  
  1823. pascal void TSmallIcon::WRes(ViewRsrcHandle theResource,
  1824.                                Ptr& itsParams) // override 
  1825. {
  1826.     inherited::WRes(theResource, itsParams);
  1827.  
  1828.     SmallIconTemplate&    templateData =
  1829.         (SmallIconTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(SmallIconTemplate)));
  1830.  
  1831. #if qDebug
  1832.     if (fRsrcID == kNoResource)
  1833.         cout << "Tried to write TSmallIcon with no resource ID.\n";
  1834. #endif
  1835.     templateData.rsrcID = fRsrcID;
  1836. }
  1837.  
  1838. //--------------------------------------------------------------------------------------------------
  1839. #pragma segment MAWriteRes
  1840.  
  1841. pascal void TSmallIcon::WriteRes(ViewRsrcHandle theResource,
  1842.                                    Ptr& itsParams) // override 
  1843. {
  1844.     gWResSignature = 'SICN'; gWResType = "TSmallIcon";
  1845.     this->WRes(theResource, itsParams);
  1846. }
  1847.  
  1848. //--------------------------------------------------------------------------------------------------
  1849. #pragma segment DlgRes
  1850.  
  1851. pascal void TSmallIcon::Draw(const VRect& area) // override 
  1852. {
  1853.     SignedByte    oldState;
  1854.     VRect        theRect;
  1855.     Rect        theQDRect;
  1856.     BitMap        srcBits;
  1857.     GrafPtr        port;
  1858.  
  1859.     
  1860. #if qDebug
  1861.     this->AssumeFocused();
  1862. #endif
  1863.     if (fDataHandle != NULL)
  1864.     {
  1865.         if (IsAResource(fDataHandle))
  1866.             LoadResource(fDataHandle);
  1867.         if ((*fDataHandle) != NULL)                     // If there's room for the small icon… 
  1868.         {
  1869.             this->ControlArea(theRect);
  1870.             this->ViewToQDRect(theRect, theQDRect);
  1871.             oldState = HGetState(fDataHandle);
  1872.             HNoPurge(fDataHandle);
  1873.             // construct a source BitMap 
  1874.             srcBits.baseAddr = (*fDataHandle);
  1875.             srcBits.rowBytes = 2;
  1876.             SetRect(srcBits.bounds, 0, 0, 16, 16);
  1877.                 
  1878.             GetPort(port);
  1879.             CopyBits(srcBits, port->portBits, srcBits.bounds, theQDRect, srcCopy, NULL);
  1880.             HSetState(fDataHandle, oldState);
  1881.         }
  1882.     }
  1883.     
  1884.     inherited::Draw(area);
  1885. }
  1886.  
  1887. //--------------------------------------------------------------------------------------------------
  1888. #pragma segment DlgNonRes
  1889.  
  1890. pascal void TSmallIcon::ReleaseSmallIcon(void)
  1891. {
  1892.     fRsrcID = kNoResource;
  1893.     if (fDataHandle != NULL)
  1894.         HPurge(fDataHandle);
  1895.     fDataHandle = NULL;
  1896. }
  1897.  
  1898. //--------------------------------------------------------------------------------------------------
  1899. #pragma segment DlgNonRes
  1900.  
  1901. pascal void TSmallIcon::SetSmallIcon(short theSmallIcon,
  1902.                                        Boolean redraw)
  1903. {
  1904.     FailInfo fi;
  1905.  
  1906.     this->ReleaseSmallIcon();
  1907.     if (! fi.CatchFailure())
  1908.     {
  1909.         fDataHandle = GetResource('SICN', theSmallIcon);
  1910.         FailResError();
  1911.         fi.Success();
  1912.     }
  1913.     else
  1914.     {
  1915.         this->Free();
  1916.         fi.ReSignal();
  1917.     }
  1918.     fRsrcID = theSmallIcon;
  1919.     if (redraw)
  1920.         this->ForceRedraw();
  1921. }
  1922.  
  1923. //--------------------------------------------------------------------------------------------------
  1924. #pragma segment DlgFields
  1925.  
  1926. pascal void TSmallIcon::Fields(TObject* obj) // override 
  1927. {
  1928.     obj->DoToField("TSmallIcon", NULL, bClass);
  1929.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  1930.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  1931.  
  1932.     inherited::Fields(obj);
  1933. }
  1934.  
  1935. //--------------------------------------------------------------------------------------------------
  1936. #pragma segment DlgOpen
  1937.  
  1938. pascal void TPattern::Initialize(void) // override 
  1939. {
  1940.     inherited::Initialize();
  1941.  
  1942.     fDataHandle = NULL;
  1943.     fPreferColor = kPreferColor;
  1944.     fIsColor = kPreferColor;
  1945.     fRsrcID = kNoResource;
  1946.  
  1947.     fDefChoice = mPatternHit;
  1948. }
  1949.  
  1950. //--------------------------------------------------------------------------------------------------
  1951. #pragma segment DlgOpen
  1952.  
  1953. pascal void TPattern::IPattern(TView* itsSuperView,
  1954.                                const VPoint& itsLocation, 
  1955.                                const VPoint& itsSize,
  1956.                                SizeDeterminer itsHSizeDet,
  1957.                                SizeDeterminer itsVSizeDet,
  1958.                                short itsRsrcID,
  1959.                                Boolean preferColor)
  1960. {
  1961.     FailInfo        fi;
  1962.  
  1963.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1964.     fPreferColor = preferColor;
  1965.     fIsColor = preferColor;
  1966.     fRsrcID = itsRsrcID;
  1967.     if (fRsrcID != kNoResource)
  1968.     {
  1969.         if (! fi.CatchFailure())
  1970.         {
  1971.             if ((fPreferColor) &&  (qNeedsColorQD || gConfiguration.hasColorQD))
  1972.                 fDataHandle = Handle(GetPixPat(fRsrcID));
  1973.             if (fDataHandle == NULL)
  1974.             {
  1975.                 fDataHandle = Handle(GetPattern(fRsrcID));
  1976.                 if (fDataHandle != NULL)
  1977.                     fIsColor = !kPreferColor;        // Either can't or won't 
  1978.             }
  1979.             FailResError();
  1980.             fi.Success();
  1981.         }
  1982.         else
  1983.         {
  1984.             this->Free();
  1985.             fi.ReSignal();
  1986.         }
  1987.     }
  1988.     this->SetEnable(False);                                    // Default is to not enable hit testing 
  1989. }
  1990.  
  1991. //--------------------------------------------------------------------------------------------------
  1992. #pragma segment DlgOpen
  1993.  
  1994. pascal void TPattern::IRes(TDocument* ,
  1995.                            TView* itsSuperView,
  1996.                            Ptr& itsParams) // override 
  1997. {
  1998.     FailInfo        fi;
  1999.     
  2000.     inherited::IRes(NULL, itsSuperView, itsParams);
  2001.  
  2002.     PatternTemplate& templateData = (PatternTemplate&) *itsParams;
  2003.     fPreferColor = templateData.preferColor;
  2004.     fIsColor = templateData.preferColor;
  2005.     fRsrcID = templateData.rsrcID;
  2006.  
  2007.     if (fRsrcID != kNoResource)
  2008.     {
  2009.         if (! fi.CatchFailure())
  2010.         {
  2011.             if ((fPreferColor) && (qNeedsColorQD || gConfiguration.hasColorQD))
  2012.                 fDataHandle = (Handle) GetPixPat(fRsrcID);
  2013.             if (fDataHandle == NULL)
  2014.             {
  2015.                 fDataHandle = (Handle) GetPattern(fRsrcID);
  2016.                 if (fDataHandle != NULL)
  2017.                     fIsColor = !kPreferColor;        // Either can't or won't 
  2018.             }
  2019.             FailResError();
  2020.             fi.Success();
  2021.         }
  2022.         else
  2023.         {
  2024.             this->Free();
  2025.             fi.ReSignal();
  2026.         }
  2027.     }
  2028.  
  2029.     OffsetPtr(itsParams, sizeof(PatternTemplate));
  2030. }
  2031.  
  2032. //--------------------------------------------------------------------------------------------------
  2033. #pragma segment DlgRes
  2034.  
  2035. pascal TObject* TPattern::Clone(void) // override 
  2036. {
  2037.     TPattern*    aClonedPattern;
  2038.     FailInfo    fi;
  2039.     Handle        aHandle;
  2040.     OSErr        err;
  2041.  
  2042.     aClonedPattern = (TPattern*)(inherited::Clone());
  2043.     
  2044.     if (fDataHandle != NULL)
  2045.     {
  2046.         if (! fi.CatchFailure())
  2047.         {
  2048.             if (fIsColor)
  2049.                 aClonedPattern->fDataHandle = (Handle) GetPixPat(fRsrcID);
  2050.             else
  2051.             {
  2052.                 aHandle = fDataHandle;
  2053.                 err = HandToHand(aHandle);
  2054.                 aClonedPattern->fDataHandle = aHandle;
  2055.             }
  2056.             FailNIL(aClonedPattern->fDataHandle);
  2057.             fi.Success();
  2058.         }
  2059.         else
  2060.         {
  2061.             aClonedPattern->Free();
  2062.             fi.ReSignal();
  2063.         }
  2064.     }
  2065.  
  2066.     return aClonedPattern;
  2067. }
  2068.  
  2069. //--------------------------------------------------------------------------------------------------
  2070. #pragma segment MAWriteRes
  2071.  
  2072. pascal void TPattern::WRes(ViewRsrcHandle theResource,
  2073.                            Ptr& itsParams) // override 
  2074. {    
  2075.     inherited::WRes(theResource, itsParams);
  2076.  
  2077.     PatternTemplate&    templateData =
  2078.         (PatternTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(PatternTemplate)));
  2079.  
  2080.     templateData.preferColor = fPreferColor;
  2081. #if qDebug
  2082.         if (fRsrcID == kNoResource)
  2083.             cout << "Tried to write TPattern with no resource ID.\n";
  2084. #endif
  2085.     templateData.rsrcID = fRsrcID;
  2086. }
  2087.  
  2088. //--------------------------------------------------------------------------------------------------
  2089. #pragma segment MAWriteRes
  2090.  
  2091. pascal void TPattern::WriteRes(ViewRsrcHandle theResource,
  2092.                                Ptr& itsParams) // override 
  2093. {
  2094.     gWResSignature = 'patn'; gWResType = "TPattern";
  2095.     this->WRes(theResource, itsParams);
  2096. }
  2097.  
  2098. //--------------------------------------------------------------------------------------------------
  2099. #pragma segment DlgClose
  2100.  
  2101. pascal void TPattern::Free(void) // override 
  2102. {
  2103.     this->ReleasePattern();
  2104.  
  2105.     inherited::Free();
  2106. }
  2107.  
  2108. //--------------------------------------------------------------------------------------------------
  2109. #pragma segment DlgRes
  2110.  
  2111. pascal void TPattern::Draw(const VRect& area) // override 
  2112. {
  2113.     Boolean        wasLocked;
  2114.     VRect        theRect;
  2115.     Rect        theQDRect;
  2116.  
  2117.     if (fDataHandle != NULL)
  2118.     {
  2119.         if (IsAResource(fDataHandle) && !fIsColor)         // Pixpat handles != resource handles 
  2120.             LoadResource(fDataHandle);
  2121.         if ((*fDataHandle) != NULL)                     // If there's room for the pattern… 
  2122.         {
  2123.             PenNormal();                                    // NECESSARY? 
  2124.             this->ControlArea(theRect);
  2125.             this->ViewToQDRect(theRect, theQDRect);
  2126.             wasLocked = IsHandleLocked(fDataHandle);    // Remember current lock state 
  2127.             if (!wasLocked)
  2128.                 HLock(fDataHandle);                     // Because FillRect may move memory 
  2129.             if (fIsColor)
  2130.                 FillCRect(theQDRect, (PixPatHandle) fDataHandle );
  2131.             else
  2132.                 FillRect(theQDRect, **((PatHandle) fDataHandle));
  2133.             if (!wasLocked)
  2134.                 HUnlock(fDataHandle);                    // restore handle's unlocked state 
  2135.         }        
  2136.     }
  2137.  
  2138.     inherited::Draw(area);
  2139. }
  2140.  
  2141. //--------------------------------------------------------------------------------------------------
  2142. #pragma segment DlgNonRes
  2143.  
  2144. pascal void TPattern::ReleasePattern(void)
  2145. {
  2146.     fRsrcID = kNoResource;
  2147.     if (fDataHandle != NULL)
  2148.     {
  2149.         if (fIsColor)
  2150.             DisposPixPat((PixPatHandle) fDataHandle);
  2151.         else
  2152.             HPurge(fDataHandle);
  2153.         fDataHandle = NULL;
  2154.     }
  2155. }
  2156.  
  2157. //--------------------------------------------------------------------------------------------------
  2158. #pragma segment DlgNonRes
  2159.  
  2160. pascal void TPattern::SetPattern(Handle thePattern,
  2161.                                    Boolean redraw)
  2162. {
  2163.     short        theID;
  2164.     ResType        theType;
  2165.     Str255        name;
  2166.     
  2167.     this->ReleasePattern();
  2168.     fDataHandle = thePattern;
  2169.     
  2170.     // get the rsrc id for non-color patterns (color pattern handles aren't resource handles) 
  2171.     if (!fIsColor)
  2172.     {
  2173.         GetResInfo(thePattern, theID, theType, name);
  2174.         if (ResError() == noErr)
  2175.             fRsrcID = theID;
  2176.     }
  2177.     
  2178.     if (redraw)
  2179.         this->ForceRedraw();
  2180. }
  2181.  
  2182. //--------------------------------------------------------------------------------------------------
  2183. #pragma segment DlgFields
  2184.  
  2185. pascal void TPattern::Fields(TObject* obj) // override 
  2186. {
  2187.     obj->DoToField("TPattern", NULL, bClass);
  2188.     obj->DoToField("fPreferColor", &fPreferColor, bBoolean);
  2189.     obj->DoToField("fIsColor", &fIsColor, bBoolean);
  2190.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  2191.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  2192.  
  2193.     inherited::Fields(obj);
  2194. }
  2195.  
  2196. //--------------------------------------------------------------------------------------------------
  2197. #pragma segment DlgOpen
  2198.  
  2199. pascal void TPicture::Initialize(void) // override 
  2200. {
  2201.     inherited::Initialize();
  2202.  
  2203.     fDataHandle = NULL;
  2204.     fRsrcID = kNoResource;
  2205.  
  2206.     fDefChoice = mPictureHit;
  2207. }
  2208.  
  2209. //--------------------------------------------------------------------------------------------------
  2210. #pragma segment DlgOpen
  2211.  
  2212. pascal void TPicture::IPicture(TView* itsSuperView,
  2213.                                const VPoint& itsLocation,
  2214.                                const VPoint& itsSize,
  2215.                                SizeDeterminer itsHSizeDet,
  2216.                                SizeDeterminer itsVSizeDet,
  2217.                                short itsRsrcID)
  2218. {
  2219.     FailInfo fi;
  2220.  
  2221.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2222.     fRsrcID = itsRsrcID;
  2223.     if (fRsrcID != kNoResource)
  2224.     {
  2225.         if (! fi.CatchFailure())
  2226.         {
  2227.             fDataHandle = GetPicture(fRsrcID);
  2228.             FailResError();
  2229.             fi.Success();
  2230.         }
  2231.         else
  2232.         {
  2233.             this->Free();
  2234.             fi.ReSignal();
  2235.         }
  2236.     }
  2237.     this->SetEnable(False);                                    // Default is to not enable hit testing 
  2238. }
  2239.  
  2240. //--------------------------------------------------------------------------------------------------
  2241. #pragma segment DlgOpen
  2242.  
  2243. pascal void TPicture::IRes(TDocument* ,
  2244.                            TView*        itsSuperView,
  2245.                            Ptr& itsParams) // override 
  2246. {
  2247.     FailInfo fi;
  2248.  
  2249.     fDataHandle = NULL;
  2250.     inherited::IRes(NULL, itsSuperView, itsParams);
  2251.  
  2252.     fRsrcID = ((PictureTemplatePtr) itsParams)->rsrcID;
  2253.     if (fRsrcID != kNoResource)
  2254.     {
  2255.         if (! fi.CatchFailure())
  2256.         {
  2257.             fDataHandle = GetPicture(fRsrcID);
  2258.             FailResError();
  2259.             fi.Success();
  2260.         }
  2261.         else
  2262.         {
  2263.             this->Free();
  2264.             fi.ReSignal();
  2265.         }
  2266.     }
  2267.  
  2268.     OffsetPtr(itsParams, sizeof(PictureTemplate));
  2269. }
  2270.  
  2271. //--------------------------------------------------------------------------------------------------
  2272. #pragma segment DlgRes
  2273.  
  2274. pascal TObject* TPicture::Clone(void) // override 
  2275. {
  2276.     TPicture*        aClonedPicture;
  2277.     FailInfo        fi;
  2278.  
  2279.     aClonedPicture = (TPicture*) (inherited::Clone());
  2280.     
  2281.     if (fDataHandle != NULL)
  2282.     {
  2283.         aClonedPicture->fDataHandle = NULL;
  2284.         if (! fi.CatchFailure())
  2285.         {
  2286.             aClonedPicture->fDataHandle = GetPicture(fRsrcID);
  2287.             FailResError();
  2288.             fi.Success();
  2289.         }
  2290.         else
  2291.         {
  2292.             aClonedPicture->Free();
  2293.             fi.ReSignal();
  2294.         }
  2295.     }
  2296.  
  2297.     return aClonedPicture;
  2298. }
  2299.  
  2300. //--------------------------------------------------------------------------------------------------
  2301. #pragma segment MAWriteRes
  2302.  
  2303. pascal void TPicture::WRes(ViewRsrcHandle theResource,
  2304.                            Ptr& itsParams) // override 
  2305. {
  2306.     inherited::WRes(theResource, itsParams);
  2307.  
  2308.     PictureTemplate&    templateData =
  2309.         (PictureTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(PictureTemplate)));
  2310.  
  2311. #if qDebug
  2312.     if (fRsrcID == kNoResource)
  2313.         cout << "Tried to write TPicture with no resource ID.\n";
  2314. #endif
  2315.     templateData.rsrcID = fRsrcID;
  2316. }
  2317.  
  2318. //--------------------------------------------------------------------------------------------------
  2319. #pragma segment MAWriteRes
  2320.  
  2321. pascal void TPicture::WriteRes(ViewRsrcHandle theResource,
  2322.                                Ptr& itsParams) // override 
  2323. {
  2324.     gWResSignature = 'pict'; gWResType = "TPicture";
  2325.     this->WRes(theResource, itsParams);
  2326. }
  2327.  
  2328. //--------------------------------------------------------------------------------------------------
  2329. #pragma segment DlgClose
  2330.  
  2331. pascal void TPicture::Free(void) // override 
  2332. {
  2333.     this->ReleasePicture();
  2334.  
  2335.     inherited::Free();
  2336. }
  2337.  
  2338. //--------------------------------------------------------------------------------------------------
  2339. #pragma segment DlgRes
  2340.  
  2341. pascal void TPicture::Draw(const VRect& area) // override 
  2342. {
  2343.     SignedByte    oldState;
  2344.     VRect        theRect;
  2345.     Rect        theQDRect;
  2346.  
  2347.     
  2348.     if (fDataHandle != NULL)
  2349.     {
  2350.         if (IsAResource( (Handle) fDataHandle))
  2351.             LoadResource((Handle) fDataHandle);
  2352.         if (*fDataHandle != NULL)                     // If there's room for the picture… 
  2353.         {
  2354.             this->ControlArea(theRect);
  2355.             this->ViewToQDRect(theRect, theQDRect);
  2356.             oldState = HGetState( (Handle) fDataHandle);
  2357.             HNoPurge((Handle) fDataHandle);
  2358.             PenNormal();                                    // ??? NECESSARY ??? 
  2359.             DrawPicture(fDataHandle, theQDRect);
  2360.             HSetState((Handle) fDataHandle, oldState);
  2361.         }
  2362.     }
  2363.     inherited::Draw(area);
  2364. }
  2365.  
  2366. //--------------------------------------------------------------------------------------------------
  2367. #pragma segment DlgNonRes
  2368.  
  2369. pascal void TPicture::ReleasePicture(void)
  2370. {
  2371.     fRsrcID = kNoResource;
  2372.     if (fDataHandle != NULL)
  2373.     {
  2374.         HPurge((Handle) fDataHandle);
  2375.         fDataHandle = NULL;
  2376.     }
  2377. }
  2378.  
  2379. //--------------------------------------------------------------------------------------------------
  2380. #pragma segment DlgNonRes
  2381.  
  2382. pascal void TPicture::SetPicture(PicHandle thePicture,
  2383.                                    Boolean redraw)
  2384. {
  2385.     short        theID;
  2386.     ResType        theType;
  2387.     Str255        name;
  2388.  
  2389.     this->ReleasePicture();
  2390.     fDataHandle = thePicture;
  2391.  
  2392.     // get the rsrc id 
  2393.     GetResInfo((Handle) thePicture, theID, theType, name);
  2394.     if (ResError() == noErr)
  2395.         fRsrcID = theID;
  2396.  
  2397.     if (redraw)
  2398.         this->ForceRedraw();
  2399. }
  2400.  
  2401. //--------------------------------------------------------------------------------------------------
  2402. #pragma segment DlgFields
  2403.  
  2404. pascal void TPicture::Fields(TObject* obj) // override 
  2405. {
  2406.     obj->DoToField("TPicture", NULL, bClass);
  2407.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  2408.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  2409.  
  2410.     inherited::Fields(obj);
  2411. }
  2412.  
  2413. //--------------------------------------------------------------------------------------------------
  2414. #pragma segment TEOpen
  2415.  
  2416. pascal void TDialogTEView::Initialize(void) // override 
  2417. {
  2418.     inherited::Initialize();
  2419.  
  2420.     fEditText = NULL;                                    /* We don't own this reference but we don't
  2421.                                                          want an invalid one either */
  2422.     fScroller = NULL;
  2423. }
  2424.  
  2425. //--------------------------------------------------------------------------------------------------
  2426. #pragma segment TEOpen
  2427.  
  2428. pascal void TDialogTEView::IDialogTEView(TDocument* itsDocument,
  2429.                                            TView*        itsSuperView,
  2430.                                            const VPoint& itsLocation,
  2431.                                          const VPoint& itsSize,
  2432.                                            SizeDeterminer itsHDeterminer,
  2433.                                          SizeDeterminer itsVDeterminer,
  2434.                                            const VRect& itsInset,
  2435.                                            const TextStyle& itsTextStyle,
  2436.                                            short itsJustification,
  2437.                                           Boolean itsStyleType, 
  2438.                                          Boolean itsAutoWrap)
  2439.  
  2440. {
  2441.     TScroller*    aScroller;
  2442.  
  2443.     
  2444.     this->ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer,
  2445.             itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
  2446.  
  2447.     aScroller = new TScroller;
  2448.     aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, 0, 0,
  2449.                         !kWantHScrollBar, !kWantVScrollBar);
  2450.     fScroller = aScroller;
  2451.     fScroller->AddSubView(this);
  2452. }
  2453.  
  2454. //--------------------------------------------------------------------------------------------------
  2455. #pragma segment TEOpen
  2456.  
  2457. pascal void TDialogTEView::IRes(TDocument* itsDocument,
  2458.                                  TView* itsSuperView,
  2459.                                  Ptr& itsParams) // override 
  2460.  
  2461. {
  2462.     TScroller*        aScroller;
  2463.  
  2464.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  2465.  
  2466.     aScroller = new TScroller;
  2467.     aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, 0, 0,
  2468.                         !kWantHScrollBar, !kWantVScrollBar);
  2469.     fScroller = aScroller;
  2470.     fScroller->AddSubView(this);
  2471. }
  2472.  
  2473. //--------------------------------------------------------------------------------------------------
  2474. #pragma segment DlgRes
  2475.  
  2476. pascal TObject* TDialogTEView::Clone(void) // override 
  2477. {
  2478.     TDialogTEView*    aClonedDialogTEView;
  2479.  
  2480.     aClonedDialogTEView = (TDialogTEView*) (inherited::Clone());
  2481.  
  2482.     aClonedDialogTEView->fEditText = NULL;    // no current edittext 
  2483.  
  2484.     if (aClonedDialogTEView->fScroller != NULL)
  2485.         aClonedDialogTEView->fScroller = (TScroller*)(aClonedDialogTEView->fScroller->Clone());
  2486.  
  2487.     return aClonedDialogTEView;
  2488. }
  2489.  
  2490. //--------------------------------------------------------------------------------------------------
  2491. #pragma segment TEClose
  2492.  
  2493. pascal void TDialogTEView::Free(void) // override 
  2494. {
  2495.     if (fScroller != NULL)
  2496.     {
  2497.         fScroller->RemoveSubView(this);
  2498.         fScroller = (TScroller*) FreeIfObject(fScroller);
  2499.     }
  2500.  
  2501.     inherited::Free();
  2502. }
  2503.  
  2504. //--------------------------------------------------------------------------------------------------
  2505. #pragma segment DlgFields
  2506.  
  2507. pascal void TDialogTEView::Fields(TObject* obj) // override 
  2508. {
  2509.     obj->DoToField("TDialogTEView", NULL, bClass);
  2510.     obj->DoToField("fEditText", &fEditText, bObject);
  2511.     obj->DoToField("fScroller", &fScroller, bObject);
  2512.  
  2513.     inherited::Fields(obj);
  2514. }
  2515.  
  2516. //--------------------------------------------------------------------------------------------------
  2517. #pragma segment DlgRes
  2518.  
  2519. pascal void TDialogTEView::BecomeTarget(void) // override 
  2520. {
  2521.     // this->InstallSelection(FALSE,TRUE); 
  2522.     inherited::BecomeTarget(); 
  2523. }
  2524.  
  2525. //--------------------------------------------------------------------------------------------------
  2526. #pragma segment DlgNonRes
  2527.  
  2528. pascal void TDialogTEView::InstallEditText(TEditText* theEditText,
  2529.                                            Boolean selectChars)
  2530.  
  2531. {
  2532.     Str255        theText;
  2533.     TextStyle    aTextStyle;
  2534.     VRect        theControlArea;
  2535.     VRect        validExtent;
  2536.     Boolean        hadPendingUpdate;
  2537.  
  2538.     if (fEditText != NULL)
  2539.     {
  2540.         fEditText->RemoveSubView(fScroller);
  2541.         fEditText = NULL;
  2542.     }
  2543.  
  2544.     if (theEditText != NULL)
  2545.     {
  2546.         fControlChars = theEditText->fControlChars;
  2547.         fMaxChars = theEditText->fMaxChars;
  2548.         fInset = gZeroVRect;
  2549.         hadPendingUpdate = theEditText->HasPendingUpdate();
  2550.  
  2551.         SetJustification(theEditText->fJust, kDontRedraw);
  2552.         ChangeWrap(theEditText->fAutoWrap, kDontRedraw);
  2553.  
  2554.         aTextStyle = theEditText->fTextStyle;
  2555.         SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
  2556.  
  2557.         theEditText->ControlArea(theControlArea);
  2558.  
  2559.         theEditText->AddSubView(fScroller);                // my scroller 
  2560.  
  2561.         if (fAutoWrap)
  2562.             fSizeDeterminer[hSel] = sizeSuperView;
  2563.         else
  2564.             fSizeDeterminer[hSel] = sizeVariable;         /* Let the width vary with the number of
  2565.                                                          characters */
  2566.  
  2567.         fSuperView->Resize(theControlArea.right - theControlArea.left, theControlArea.bottom - theControlArea.top, kDontInvalidate);
  2568.         fSuperView->Locate(theControlArea.left, theControlArea.top, kDontInvalidate);
  2569.  
  2570.         theEditText->GetText(theText);
  2571.         this->SetText(theText);
  2572.         this->RecalcText();
  2573.         this->SynchView(kDontRedraw);
  2574.         this->AdjustSize();
  2575.  
  2576.         // Make the scroller's thinking match the display that the user already sees 
  2577.         fScroller->fTranslation.h = 0;
  2578.         switch (GetActualJustification(fJustification))
  2579.         {
  2580.             case teFlushDefault:
  2581.             case teFlushLeft:
  2582.                 fScroller->fTranslation.v = 0;
  2583.                 break;
  2584.             case teFlushRight:                /* Right brain thinkers… left brain thinkers?? */
  2585.                 ((TScroller*) fSuperView)->fTranslation.h = fScroller->fMaxTranslation.h;
  2586.                 break;
  2587.             case teCenter:
  2588.                 fScroller->fTranslation.h = fScroller->fMaxTranslation.h / 2;
  2589.                 break;
  2590.         }
  2591.         theEditText->InvalidateFocus();
  2592.         theEditText->UpdateCoordinates();
  2593.  
  2594.         if (selectChars)
  2595.             SetSelect(0, MAXINT, fHTE);
  2596.         else
  2597.             SetSelect(0, 0, fHTE);                        // Caller will set the selection. 
  2598.  
  2599.         this->BeInScroller(fScroller);
  2600.  
  2601.         // Make my enable and my scroller's enable match my new superview 
  2602.         this->SetEnable(theEditText->IsEnabled());
  2603.         fScroller->SetEnable(theEditText->IsEnabled());
  2604.  
  2605.         // Revalidate my extent to eliminate the flicker created by resizing the scrollers 
  2606.         //!!! RCR && SRF Revisit this
  2607. #if FALSE
  2608.         if (!hadPendingUpdate)
  2609.             {
  2610.             GetExtent(validExtent);
  2611.             ValidateVRect(validExtent);
  2612.             }
  2613. #endif
  2614.     }
  2615.  
  2616.     fEditText = theEditText;
  2617. }
  2618.  
  2619. //--------------------------------------------------------------------------------------------------
  2620. #pragma segment DlgNonRes
  2621.  
  2622. pascal void TDialogTEView::InstallSelection(Boolean wasActive, 
  2623.                                             Boolean beActive) // override 
  2624.  
  2625. {
  2626.  /* If we're deselecting a field and it's been scrolled, invalidate it
  2627.   so that it is redrawn correctly.*/
  2628. /*    if (!beActive)
  2629.         if (fScroller->fTranslation.v != 0)
  2630.             this->ForceRedraw();
  2631.         else
  2632.         {
  2633.             switch ( GetActualJustification(fJustification) )
  2634.             {
  2635.                 case teFlushDefault:
  2636.                 case teFlushLeft:
  2637.                     if (fScroller->fTranslation.h != 0)
  2638.                         this->ForceRedraw();
  2639.                         break;
  2640.                 case teFlushRight:
  2641.                     if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
  2642.                         this->ForceRedraw();
  2643.                         break;
  2644.                 case teCenter:
  2645.                     if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
  2646.                         this->ForceRedraw();
  2647.                     break;
  2648.             }
  2649.         }
  2650. */
  2651.     inherited::InstallSelection(wasActive, beActive);
  2652. }
  2653.  
  2654. //--------------------------------------------------------------------------------------------------
  2655. #pragma segment DlgRes
  2656.  
  2657. pascal void TDialogTEView::ResignTarget(void) // override 
  2658. {
  2659.     inherited::ResignTarget(); 
  2660.  
  2661. /* If we're deselecting a field and it's been scrolled, invalidate it
  2662.   so that it is redrawn correctly.*/
  2663.     if (fScroller->fTranslation.v != 0)
  2664.         this->ForceRedraw();
  2665.     else
  2666.     {
  2667.         switch ( GetActualJustification(fJustification) )
  2668.         {
  2669.             case teFlushDefault:
  2670.             case teFlushLeft:
  2671.                 if (fScroller->fTranslation.h != 0)
  2672.                     this->ForceRedraw();
  2673.                     break;
  2674.             case teFlushRight:
  2675.                 if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
  2676.                     this->ForceRedraw();
  2677.                     break;
  2678.             case teCenter:
  2679.                 if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
  2680.                     this->ForceRedraw();
  2681.                 break;
  2682.         }
  2683.     }
  2684.     
  2685.     if (fEditText != NULL)
  2686.         fEditText->StopEdit();
  2687.     
  2688. }
  2689.  
  2690. //--------------------------------------------------------------------------------------------------
  2691. #pragma segment DlgRes
  2692.  
  2693. pascal void TDialogTEView::CantDeselect(long reason) // override 
  2694. {
  2695.     if (fEditText != NULL)
  2696.         fEditText->CantDeselect(reason);
  2697. }
  2698.  
  2699. //--------------------------------------------------------------------------------------------------
  2700. #pragma segment DlgRes
  2701.  
  2702. pascal long TDialogTEView::WillingToResignTarget(void) // override 
  2703. {
  2704.     TCommand*    lastCommand;
  2705.     long        result;
  2706.  
  2707.     result = 0;
  2708.  
  2709.     if (fEditText != NULL)
  2710.     {
  2711.         lastCommand = this->GetLastCommand();
  2712.         if ( (lastCommand != NULL) && (lastCommand->fView == this) )
  2713.             this->CommitLastCommand();
  2714.     
  2715.         result = fEditText->Validate();
  2716.     }
  2717.     return result;
  2718. }
  2719.  
  2720. //--------------------------------------------------------------------------------------------------
  2721. #pragma segment DlgNonRes
  2722.  
  2723. pascal void TDialogTEView::ComputeSize(VPoint& newSize) // override 
  2724. {
  2725.     inherited::ComputeSize(newSize);
  2726.  
  2727.     if (!fAutoWrap)
  2728.         switch (fSizeDeterminer[hSel])
  2729.         {
  2730.             case sizeVariable:
  2731.                 /* TTEView already computed the variable size, bump it up to at leat the scroller's
  2732.                 size so that the cursor is claimed for the EditText and the user can click anywhere. */
  2733.                 if (!fStyleType)
  2734.                     newSize.h = Max(fScroller->fSize.h, newSize.h);
  2735.         }
  2736. }
  2737.  
  2738. //--------------------------------------------------------------------------------------------------
  2739. #pragma segment DlgOpen
  2740.  
  2741. pascal void TStaticText::Initialize(void) // override 
  2742. {
  2743.     inherited::Initialize();
  2744.  
  2745.     fDataHandle = NULL;
  2746.     fRsrcID = kNoResource;
  2747.     fIndex = 0;
  2748.     fJust = teFlushDefault;                                // Default to system justification 
  2749.     fAutoWrap = TRUE;                                    // Default to compatibility with 2.0 
  2750.  
  2751.     fDefChoice = mStaticTextHit;
  2752. }
  2753.  
  2754. //--------------------------------------------------------------------------------------------------
  2755. #pragma segment DlgOpen
  2756.  
  2757. pascal void TStaticText::IStaticText(TView* itsSuperView,
  2758.                                        const VPoint& itsLocation,
  2759.                                      const VPoint& itsSize,
  2760.                                        SizeDeterminer itsHSizeDet,
  2761.                                      SizeDeterminer itsVSizeDet,
  2762.                                        short itsRsrcID,
  2763.                                      short itsIndex)
  2764. {
  2765.     Str255        aString;
  2766.     FailInfo        fi;
  2767.  
  2768.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2769.     fRsrcID = itsRsrcID;
  2770.     fIndex = itsIndex;
  2771.     //fJust = teFlushDefault; */                            /* Default to system justification 
  2772.     //fAutoWrap = TRUE; */                                /* Default to compatibility with 2.0 
  2773.     if (fRsrcID != kNoResource)
  2774.     {
  2775.         if (! fi.CatchFailure())
  2776.         {
  2777.             GetIndString(aString, fRsrcID, fIndex);
  2778.             FailResError();
  2779.             fi.Success();
  2780.         }
  2781.         else
  2782.         {
  2783.             this->Free();
  2784.             fi.ReSignal();
  2785.         }
  2786.         SetText(aString, kDontRedraw);
  2787.     }
  2788.     this->SetEnable(False);                                    // Default is to not enable hit testing 
  2789. }
  2790.  
  2791. //--------------------------------------------------------------------------------------------------
  2792. #pragma segment DlgOpen
  2793.  
  2794. pascal void TStaticText::IRes(TDocument* ,
  2795.                                  TView* itsSuperView,
  2796.                                  Ptr& itsParams) // override 
  2797. {
  2798.     inherited::IRes(NULL, itsSuperView, itsParams);
  2799.  
  2800.     //fAutoWrap = TRUE; */                                /* Default to compatibility with 2.0 
  2801.     //fDefChoice = mStaticTextHit;
  2802.  
  2803.     StaticTextTemplate& templateData = (StaticTextTemplate&) *itsParams;
  2804.  
  2805.     fJust = templateData.just;
  2806.     SetText(templateData.data, kDontRedraw);
  2807.  
  2808.     OffsetPtrWStr(itsParams, sizeof(StaticTextTemplate));
  2809. }
  2810.  
  2811. //--------------------------------------------------------------------------------------------------
  2812. #pragma segment DlgRes
  2813.  
  2814. pascal TObject* TStaticText::Clone(void) // override 
  2815. {
  2816.     TStaticText*        aClonedStaticText;
  2817.     StringHandle        newString;
  2818.     
  2819.     aClonedStaticText = (TStaticText*)(inherited::Clone());
  2820.  
  2821.     newString = aClonedStaticText->fDataHandle;
  2822.     if (newString != NULL)
  2823.         FailOSErr(HandToHand((Handle) newString));
  2824.     aClonedStaticText->fDataHandle = newString;
  2825.  
  2826.     return aClonedStaticText;
  2827. }
  2828.  
  2829. //--------------------------------------------------------------------------------------------------
  2830. #pragma segment MAWriteRes
  2831.  
  2832. pascal void TStaticText::WRes(ViewRsrcHandle theResource,
  2833.                                  Ptr& itsParams) // override 
  2834. {
  2835.     Str255                    theText;
  2836.     
  2837.     inherited::WRes(theResource, itsParams);
  2838.  
  2839.     this->GetText(theText);
  2840.  
  2841.     StaticTextTemplate&    templateData =
  2842.         (StaticTextTemplate&) *(ExpandPtrWStr( (Handle) theResource, itsParams, sizeof(StaticTextTemplate),
  2843.                                                  theText.Length()));
  2844.  
  2845.     templateData.just = fJust;
  2846.     // templateData.data = theText; 
  2847.     CopyStr255(theText, PRStr(templateData.data));
  2848. }
  2849.  
  2850. //--------------------------------------------------------------------------------------------------
  2851. #pragma segment MAWriteRes
  2852.  
  2853. pascal void TStaticText::WriteRes(ViewRsrcHandle theResource,
  2854.                                      Ptr& itsParams) // override 
  2855. {
  2856.     gWResSignature = 'stat'; gWResType = "TStaticText";
  2857.     this->WRes(theResource, itsParams);
  2858. }
  2859.  
  2860. //--------------------------------------------------------------------------------------------------
  2861. #pragma segment DlgClose
  2862.  
  2863. pascal void TStaticText::Free(void) // override 
  2864. {
  2865.     this->ReleaseText();
  2866.  
  2867.     inherited::Free();
  2868. }
  2869.  
  2870. //--------------------------------------------------------------------------------------------------
  2871. #pragma segment DlgRes
  2872.  
  2873. pascal void TStaticText::ChangeWrap(Boolean newAutoWrap, 
  2874.                                     Boolean redraw)
  2875. {
  2876.     fAutoWrap = newAutoWrap;
  2877.     if (redraw)
  2878.         this->ForceRedraw();
  2879. }
  2880.  
  2881. //--------------------------------------------------------------------------------------------------
  2882. #pragma segment DlgRes
  2883.  
  2884. pascal void TStaticText::DoSubstitution(Str255& theText)
  2885.  
  2886. {
  2887.     MAReplaceText(theText);
  2888. }
  2889.  
  2890. //--------------------------------------------------------------------------------------------------
  2891. #pragma segment DlgRes
  2892.  
  2893. pascal void TStaticText::Draw(const VRect& area) // override 
  2894. {
  2895.     VRect        theRect;
  2896.     RGBColor        oldColor;
  2897.     Str255        theText;
  2898.     TextStyle        aTextStyle;
  2899.  
  2900.     if (fDataHandle != NULL)
  2901.     {
  2902.         this->GetText(theText);
  2903.         this->DoSubstitution(theText);                        // Make the substitution if desired 
  2904.         this->ControlArea(theRect);
  2905.         PenNormal();                                        // ??? NECESSARY ??? 
  2906.         GetIfColor(oldColor);
  2907.         aTextStyle = fTextStyle;
  2908.         SetPortTextStyle(aTextStyle);
  2909.         this->ImageText(Ptr(((long)&theText) + 1), theText.Length(), theRect, fJust);
  2910.         SetIfColor(oldColor);
  2911.     }
  2912.     inherited::Draw(area);
  2913. }
  2914.  
  2915. //--------------------------------------------------------------------------------------------------
  2916. #pragma segment DlgRes
  2917.  
  2918. pascal void TStaticText::GetText(Str255& theText)
  2919. {
  2920.     if (fDataHandle != NULL)
  2921.     // theText = (*fDataHandle)^ 
  2922.         CopyStr255((**((RCRStringHandle) fDataHandle)), (Ptr)&theText);
  2923.     else
  2924.         theText = "";
  2925. }
  2926.  
  2927. //--------------------------------------------------------------------------------------------------
  2928. #pragma segment DlgRes
  2929.  
  2930. pascal void TStaticText::ImageText(Ptr text,
  2931.                                    long Length,
  2932.                                    const VRect& box,
  2933.                                    short just)
  2934. {
  2935.     Rect        qdBox;
  2936.  
  2937.     this->ViewToQDRect(box, qdBox);
  2938.     MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
  2939. }
  2940.  
  2941. //--------------------------------------------------------------------------------------------------
  2942. #pragma segment DlgNonRes
  2943.  
  2944. pascal void TStaticText::ReleaseText(void)
  2945. {
  2946.     fDataHandle = (StringHandle) DisposeIfHandle( (Handle) fDataHandle);
  2947.  
  2948.     fRsrcID = kNoResource;
  2949. }
  2950.  
  2951. //--------------------------------------------------------------------------------------------------
  2952. #pragma segment DlgNonRes
  2953.  
  2954. pascal void TStaticText::SetJustification(short theJust,
  2955.                                              Boolean redraw)
  2956. {
  2957.     fJust = theJust;
  2958.     if (redraw)
  2959.         this->ForceRedraw();
  2960. }
  2961.  
  2962. //--------------------------------------------------------------------------------------------------
  2963. #pragma segment DlgNonRes
  2964.  
  2965. pascal void TStaticText::SetText(const Str255& theText,
  2966.                               Boolean redraw)
  2967. {
  2968.     VRect        area;
  2969.     Rect        qdArea;
  2970.  
  2971.     
  2972.     if ( (fDataHandle == NULL) || (theText != (**((RCRStringHandle) fDataHandle))) )
  2973.     {
  2974.         this->ReleaseText();
  2975.         fDataHandle = NewString(theText);
  2976.         if (MemError() != noErr)
  2977.             fDataHandle = NULL;
  2978.         if (redraw && this->IsDrawable())
  2979.         {
  2980.             this->ControlArea(area);
  2981.             this->ViewToQDRect(area, qdArea);
  2982.             EraseRect(qdArea);
  2983.             this->Draw(area);
  2984.         }
  2985.     }
  2986. }
  2987.  
  2988. //--------------------------------------------------------------------------------------------------
  2989. #pragma segment DlgFields
  2990.  
  2991. pascal void TStaticText::Fields(TObject* obj) // override 
  2992. {
  2993.     Str255        aString;
  2994.  
  2995.     obj->DoToField("TStaticText", NULL, bClass);
  2996.     obj->DoToField("fRsrcID", &fRsrcID, bInteger);
  2997.     obj->DoToField("fIndex", &fIndex, bInteger);
  2998.     obj->DoToField("fDataHandle", &fDataHandle, bHandle);
  2999.     if (fDataHandle != NULL)
  3000.     {
  3001.         aString = (**((RCRStringHandle) fDataHandle));
  3002.         DoToField("(**fDataHandle)", &aString, bString);
  3003.     }
  3004.     obj->DoToField("fJust", &fJust, bInteger);
  3005.     obj->DoToField("fAutoWrap", &fAutoWrap, bBoolean);
  3006.  
  3007.     inherited::Fields(obj);
  3008. }
  3009.  
  3010. //--------------------------------------------------------------------------------------------------
  3011. #pragma segment DlgOpen
  3012.  
  3013. pascal void TEditText::Initialize(void) // override 
  3014. {
  3015.     inherited::Initialize();
  3016.  
  3017.     fTEView = NULL;
  3018.     fMaxChars = 255;                                    // Is there a constant? 
  3019. //RCR    fControlChars = [chLeft, chRight, chUp, chDown, chBackspace];
  3020.     fControlChars = __SetBit__(chLeft) |
  3021.                     __SetBit__(chRight) |
  3022.                     __SetBit__(chUp) |
  3023.                     __SetBit__(chDown) |
  3024.                     __SetBit__(chBackspace);
  3025.  
  3026.     fTextStyle = gSystemStyle;
  3027. //    fPenSize = Point(1,1);                        // …and a thin frame 
  3028.     fPenSize.v = 1;
  3029.     fPenSize.h = 1;
  3030.     SetAdornment(kFrame, kDontRedraw);
  3031.     fAutoWrap = False;                                 /* Default to compatibility with 2.0 Never
  3032.                                                          the twain shall meet.*/
  3033.     fDefChoice = mEditTextHit;
  3034. }
  3035.  
  3036. //--------------------------------------------------------------------------------------------------
  3037. #pragma segment DlgOpen
  3038.  
  3039. pascal void TEditText::IEditText(TView* itsSuperView,
  3040.                                    const VPoint& itsLocation,
  3041.                                  const VPoint& itsSize,
  3042.                                    short itsMaxChars)
  3043. {
  3044.     this->IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
  3045.  
  3046.     fAutoWrap = False;                                 /* Default to compatibility with 2.0 Never
  3047.                                                          the twain shall meet.*/
  3048.     fMaxChars = itsMaxChars;
  3049. //RCR    fControlChars = [chLeft, chRight, chUp, chDown, chBackspace];
  3050.     fControlChars = __SetBit__(chLeft) |
  3051.                     __SetBit__(chRight) |
  3052.                     __SetBit__(chUp) |
  3053.                     __SetBit__(chDown) |
  3054.                     __SetBit__(chBackspace);
  3055.     fTextStyle = gSystemStyle;
  3056.     Inset(3, 3, kDontRedraw);                            // Default is a little, teeny inset… 
  3057. //    fPenSize = Point(1,1);                        // …and a thin frame 
  3058.     fPenSize.v = 1;
  3059.     fPenSize.h = 1;
  3060.     this->SetAdornment(kFrame, kDontRedraw);
  3061.     this->SetEnable(TRUE);
  3062.     fDefChoice = mEditTextHit;
  3063. }
  3064.  
  3065. //--------------------------------------------------------------------------------------------------
  3066. #pragma segment DlgOpen
  3067.  
  3068. pascal void TEditText::IRes(TDocument* ,
  3069.                              TView* itsSuperView,
  3070.                              Ptr& itsParams) // override 
  3071. {
  3072.     inherited::IRes(NULL, itsSuperView, itsParams);
  3073.  
  3074.     fAutoWrap = False;                                 /* Default to compatibility with 2.0 Never
  3075.                                                          the twain shall meet.*/
  3076.     EditTextTemplate& templateData = (EditTextTemplate&) *itsParams;
  3077.  
  3078.     fMaxChars = templateData.maxChars;
  3079.     fControlChars = templateData.controlChars;
  3080.     
  3081.     fDefChoice = mEditTextHit;
  3082.  
  3083.     OffsetPtr(itsParams, sizeof(EditTextTemplate));
  3084. }
  3085.  
  3086. //--------------------------------------------------------------------------------------------------
  3087. #pragma segment DlgRes
  3088.  
  3089. pascal TObject* TEditText::Clone(void) // override 
  3090. {
  3091.     TEditText*    aClonedEditText;
  3092.  
  3093.     aClonedEditText = (TEditText*)(inherited::Clone());
  3094.  
  3095.     aClonedEditText->fTEView = NULL;
  3096.  
  3097.     return aClonedEditText;
  3098.     }
  3099.  
  3100. //--------------------------------------------------------------------------------------------------
  3101. #pragma segment DlgClose
  3102.  
  3103. pascal void TEditText::Free(void) // override 
  3104.  
  3105. {
  3106.     this->RemoveFloatingTEView();
  3107.     inherited::Free();
  3108. }
  3109.  
  3110. //--------------------------------------------------------------------------------------------------
  3111. #pragma segment MAWriteRes
  3112.  
  3113. pascal void TEditText::WRes(ViewRsrcHandle theResource,
  3114.                              Ptr& itsParams) // override 
  3115. {
  3116.     inherited::WRes(theResource, itsParams);
  3117.  
  3118.     EditTextTemplate&    templateData =
  3119.         (EditTextTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(EditTextTemplate)));
  3120.  
  3121.     templateData.maxChars = fMaxChars;
  3122.     templateData.controlChars = fControlChars;
  3123. }
  3124.  
  3125. //--------------------------------------------------------------------------------------------------
  3126. #pragma segment MAWriteRes
  3127.  
  3128. pascal void TEditText::WriteRes(ViewRsrcHandle theResource,
  3129.                                  Ptr& itsParams) // override 
  3130. {
  3131.     gWResSignature = 'edit'; gWResType = "TEditText";
  3132.     WRes(theResource, itsParams);
  3133. }
  3134.  
  3135. //--------------------------------------------------------------------------------------------------
  3136. #pragma segment DlgRes
  3137.  
  3138. pascal void TEditText::BecomeTarget(void) // override 
  3139. {
  3140.     this->StartEdit(TRUE);
  3141.  
  3142.     inherited::BecomeTarget();
  3143. }
  3144.  
  3145. //--------------------------------------------------------------------------------------------------
  3146. #pragma segment DlgNonRes
  3147.  
  3148. pascal void TEditText::CantDeselect(long reason)
  3149. {
  3150.     Str255        aString;
  3151.  
  3152.     if (reason != kValidValue)
  3153.     {
  3154.         if (reason != kErrorHandled)                 // go ahead and post an alert 
  3155.         {
  3156.             if ( (reason < 1) || (reason > kNoOfDefaultReasons) )
  3157.                 reason = kInvalidValue;
  3158.  
  3159.             GetIndString(aString, (short) kInvalidValueReasons, (short) reason); //!!! Note casting
  3160.             ParamText(aString, "", "", "");
  3161.             StdAlert(phInvalidValue);
  3162.         }
  3163.         aString = (**((RCRStringHandle) fDataHandle));            // Restart with previous value 
  3164.         this->RestartEdit(aString);
  3165.     }
  3166. }
  3167.  
  3168. //--------------------------------------------------------------------------------------------------
  3169. #pragma segment DlgRes
  3170.  
  3171. pascal void TEditText::ChangeWrap(Boolean newAutoWrap, 
  3172.                                   Boolean redraw) // override 
  3173. {
  3174.     inherited::ChangeWrap(newAutoWrap, redraw);
  3175.     if (fTEView != NULL)
  3176.         fTEView->ChangeWrap(newAutoWrap, redraw);
  3177. }
  3178.  
  3179. //--------------------------------------------------------------------------------------------------
  3180. #pragma segment DlgRes
  3181.  
  3182. pascal Boolean TEditText::HandleMouseDown(const VPoint& theMouse,
  3183.                                              TDeviceEvent* event,
  3184.                                              Point& hysteresis) // override 
  3185.  
  3186. {
  3187.     return inherited::HandleMouseDown(theMouse, event, hysteresis);
  3188. }
  3189.  
  3190. //--------------------------------------------------------------------------------------------------
  3191. #pragma segment DlgRes
  3192.  
  3193. pascal Boolean TEditText::Deselect(void)
  3194. {
  3195.     long        validateResult;
  3196.     TCommand*    lastCommand;
  3197.     Boolean        result;
  3198.  
  3199.     
  3200.     result = TRUE;
  3201.  
  3202.     /* Commit the last command to prevent undo from applying to the wrong edit text,
  3203.     and to ensure that all changes are made before validating. */
  3204.     if (fTEView != NULL)
  3205.     {
  3206.         lastCommand = fTEView->GetLastCommand();
  3207.         if ( (lastCommand != NULL) && (lastCommand->fView == fTEView))
  3208.             fTEView->CommitLastCommand();
  3209.     }
  3210.  
  3211.     validateResult = this->Validate();
  3212.     if (validateResult == kValidValue)
  3213.         this->StopEdit();
  3214.     else
  3215.     {
  3216.         this->CantDeselect(validateResult);
  3217.         result = FALSE;
  3218.     }
  3219.     return result;
  3220. }
  3221.  
  3222. //--------------------------------------------------------------------------------------------------
  3223. #pragma segment DlgRes
  3224.  
  3225. pascal void TEditText::DoSubstitution(Str255& theText) // override 
  3226. {
  3227.     // Default action is for editable text items is not to do any substitions 
  3228. }
  3229.  
  3230. //--------------------------------------------------------------------------------------------------
  3231. #pragma segment DlgFields
  3232.  
  3233. pascal void TEditText::Fields(TObject* obj) // override 
  3234. {
  3235.     obj->DoToField("TEditText", NULL, bClass);
  3236.     obj->DoToField("fMaxChars", &fMaxChars, bInteger);
  3237.     obj->DoToField("fTEView", &fTEView, bObject);
  3238.     obj->DoToField("fControlChars", &fControlChars, bHexLongInt);
  3239.  
  3240.     inherited::Fields(obj);
  3241. }
  3242.  
  3243. //--------------------------------------------------------------------------------------------------
  3244. #pragma segment DlgRes
  3245.  
  3246. pascal void TEditText::GetText(Str255& theText) // override 
  3247. {
  3248.     Handle        theChars;
  3249.     short        numberOfChars;
  3250.  
  3251.     
  3252.     if (fTEView == NULL)
  3253.         inherited::GetText(theText);
  3254.     else
  3255.     {
  3256.         theChars = fTEView->ExtractText();
  3257.         numberOfChars = (short) Min(255, GetHandleSize(theChars)); //!!! Note cast
  3258.         theText[0] = ((char)(numberOfChars));
  3259.         BlockMove( (Ptr)(*theChars), (Ptr)(((long)&theText) + 1), numberOfChars);
  3260.     }
  3261. }
  3262.  
  3263. //--------------------------------------------------------------------------------------------------
  3264. #pragma segment DlgRes
  3265.  
  3266. pascal void TEditText::ImageText(Ptr text,
  3267.                                    long Length,
  3268.                                    const VRect& box,
  3269.                                    short just) // override 
  3270. {
  3271.     Rect qdBox;
  3272.  
  3273.     if (Length >= 0)
  3274.     {
  3275.         this->ViewToQDRect(box, qdBox);
  3276.         MATextBox(text, Length, qdBox, just, fAutoWrap, NULL, kNoEraseFirst, kSpaceForCaret);
  3277.     }
  3278. }
  3279.  
  3280. //--------------------------------------------------------------------------------------------------
  3281. #pragma segment DlgRes
  3282.  
  3283. pascal void TEditText::InstallFloatingTEView(Boolean selectChars)
  3284. {
  3285.     TDialogTEView*    aFloatingTEView;
  3286.  
  3287.     if (fTEView == NULL)
  3288.     {
  3289.         aFloatingTEView = AquireFloatingTEView();
  3290.         if (aFloatingTEView == NULL)
  3291.         {
  3292. #if qDebug
  3293.             ProgramBreak("###the aquired TEView is nil.");
  3294. #endif
  3295. //RCR            exit(InstallFloatingTEView);
  3296.         }
  3297.         aFloatingTEView->InstallEditText(this, selectChars);
  3298.         fTEView = aFloatingTEView;
  3299.     }
  3300.  
  3301.     // since the floating TE view handles dim/hilite drawing - these adorners are removed 
  3302.     if (fDimmed)
  3303.         this->DeleteAdorner(gDimAdorner, kDontRedraw);
  3304.     if (fHilite)
  3305.         this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
  3306. }
  3307.  
  3308. //--------------------------------------------------------------------------------------------------
  3309. #pragma segment DlgRes
  3310. pascal void TEditText::MakeVisible(void)
  3311. {
  3312.     VRect        myExtent;
  3313.     VPoint        minToSee;
  3314.  
  3315.     this->GetExtent(myExtent);
  3316.     InsetVRect(myExtent, - 10, - 10);
  3317.     minToSee.h = Min(fSize.h + 10, kMaxCoord);
  3318.     minToSee.v = Min(fSize.v + 10, kMaxCoord);
  3319.  
  3320.     this->RevealRect(myExtent, minToSee, kVisible);            
  3321. }
  3322.  
  3323. //--------------------------------------------------------------------------------------------------
  3324. #pragma segment DlgRes
  3325.  
  3326. pascal void TEditText::RemoveFloatingTEView(void)
  3327. {
  3328.     if (fTEView != NULL)
  3329.     {
  3330.         fTEView->InstallEditText(NULL, False);
  3331. /*!!!*/    ReleaseFloatingTEView(fTEView);
  3332.         fTEView = NULL;
  3333.     }
  3334.  
  3335.     // since the floating TE view handles dim/hilite drawing - these adorners were removed 
  3336.     if (fDimmed)
  3337.         AddAdorner(gDimAdorner, kDontRedraw);
  3338.     if (fHilite)
  3339.         AddAdorner(gHiliteAdorner, kDontRedraw);
  3340. }
  3341.  
  3342. //--------------------------------------------------------------------------------------------------
  3343. #pragma segment DlgNonRes
  3344.  
  3345. pascal void TEditText::RestartEdit(const Str255& restartText)
  3346. {
  3347.     Rect    area;
  3348.  
  3349.     if (fTEView->Focus())                                // First, attempt to focus the TEView 
  3350.     {
  3351.         ClipRect(gZeroRect);                            /* Prevent TE from mucking up the hilite with
  3352.                                                          a stinking insertion point */
  3353.  
  3354.         //!!!RCR InstallSelection(TRUE, False);    
  3355.         fTEView->SetActive(FALSE);                        // Deactivate the selection 
  3356.         SetText(restartText, kDontRedraw);                // Set the text to previous value 
  3357.         SetSelection(0, MAXINT, kDontRedraw);            // Select all characters 
  3358.  
  3359.         //!!!RCR InstallSelection(False, TRUE);    */        /* Activate the selection 
  3360.         fTEView->SetActive(TRUE);
  3361.         
  3362.         this->InvalidateFocus();                                // Make sure we re-focus 
  3363.         fTEView->ForceRedraw();
  3364.     }    
  3365.     else
  3366.         SetText(restartText, kDontRedraw);                // Just set the text if we can't focus 
  3367. }
  3368.  
  3369. //--------------------------------------------------------------------------------------------------
  3370. #pragma segment DlgNonRes
  3371.  
  3372. pascal void TEditText::SetJustification(short theJust,
  3373.                                         Boolean redraw)
  3374. {
  3375.     if (fTEView != NULL)
  3376.         fTEView->SetJustification(theJust, redraw);
  3377.     inherited::SetJustification(theJust, redraw);
  3378. }
  3379.  
  3380. //--------------------------------------------------------------------------------------------------
  3381. #pragma segment DlgRes
  3382.  
  3383. pascal void TEditText::SetSelection(short selStart, 
  3384.                                     short selEnd,
  3385.                                      Boolean redraw)
  3386. {
  3387.     if (fTEView != NULL)
  3388.     {
  3389.         if (redraw && fTEView->IsDrawable())
  3390.             TESetSelect(selStart, selEnd, fTEView->fHTE);
  3391.         else
  3392.             SetSelect(selStart, selEnd, fTEView->fHTE);
  3393.     }
  3394. }
  3395.  
  3396. //--------------------------------------------------------------------------------------------------
  3397. #pragma segment DlgNonRes
  3398.  
  3399. pascal void TEditText::SetText(const Str255& theText,
  3400.                                Boolean redraw) // override 
  3401. {
  3402.     Str255        currentText;
  3403.     VRect        area;
  3404.     Rect        qdArea;
  3405.  
  3406.     if (fTEView != NULL)
  3407.     {
  3408.         this->GetText(currentText);
  3409.         if (currentText != theText)
  3410.         {
  3411.             fTEView->SetText(theText);
  3412.             fTEView->RecalcText();
  3413.             fTEView->SynchView(kDontRedraw);
  3414.             if (redraw && this->IsDrawable())
  3415.             {
  3416.                 this->ControlArea(area);
  3417.                 this->ViewToQDRect(area, qdArea);
  3418.                 EraseRect(qdArea);
  3419.                 this->DrawContents();
  3420.             }
  3421.         }
  3422.     }    
  3423.     else
  3424.         inherited::SetText(theText, redraw);
  3425. }
  3426.  
  3427. //--------------------------------------------------------------------------------------------------
  3428. #pragma segment DlgRes
  3429.  
  3430. pascal void TEditText::InstallSelection(Boolean wasActive, 
  3431.                                         Boolean beActive) // override 
  3432. {
  3433.     if (fTEView != NULL)
  3434.         fTEView->InstallSelection(wasActive, beActive);
  3435.     else if (beActive)
  3436. /*!!!RCR*/ this->StartEdit(TRUE);
  3437. }
  3438.  
  3439. //--------------------------------------------------------------------------------------------------
  3440. #pragma segment DlgRes
  3441.  
  3442. pascal void TEditText::ResignTarget(void) // override 
  3443. {
  3444.     inherited::ResignTarget();
  3445. }
  3446.  
  3447. //--------------------------------------------------------------------------------------------------
  3448. #pragma segment DlgNonRes
  3449.  
  3450. pascal void TEditText::StartEdit(Boolean selectChars)
  3451. {
  3452.     this->InstallFloatingTEView(selectChars);
  3453.     this->SetTarget(fTEView);             
  3454.  
  3455.     this->MakeVisible();
  3456. }
  3457.  
  3458. //--------------------------------------------------------------------------------------------------
  3459. #pragma segment DlgNonRes
  3460.  
  3461. pascal void TEditText::StopEdit(void)
  3462. {
  3463.     Str255        aString;
  3464.  
  3465.     if (fTEView != NULL)
  3466.     {
  3467.         this->GetText(aString);                            /* Must get the text before removing
  3468.                                                          the floating TEView */
  3469.         // fTEView->InstallSelection(TRUE, FALSE); 
  3470.         this->RemoveFloatingTEView();
  3471.         this->SetText(aString, kDontRedraw);
  3472.     }
  3473. }
  3474.  
  3475. //--------------------------------------------------------------------------------------------------
  3476. #pragma segment DlgRes
  3477.  
  3478. pascal long TEditText::Validate(void)
  3479. {
  3480.     long        validateResult;
  3481.     
  3482.     validateResult = inherited::Validate();
  3483.     if ((validateResult == kValidValue) 
  3484.             && (fTEView != NULL) 
  3485.             && (GetHandleSize(fTEView->fText) > fMaxChars))
  3486.         validateResult = kTooManyCharacters;
  3487.     return validateResult;
  3488. }
  3489.  
  3490. //--------------------------------------------------------------------------------------------------
  3491. #pragma segment DlgRes
  3492. pascal Boolean TEditText::WantToBecomeTarget(void) // override 
  3493. {
  3494.     return ( (fTEView == NULL)  && this->IsEnabled()) /* && this.IsActive*/;
  3495. }
  3496.  
  3497. //--------------------------------------------------------------------------------------------------
  3498. #pragma segment DlgRes
  3499.  
  3500. pascal long TEditText::WillingToResignTarget(void) // override 
  3501. {
  3502.     return inherited::WillingToResignTarget();
  3503. }
  3504.  
  3505. //--------------------------------------------------------------------------------------------------
  3506. #pragma segment DlgOpen
  3507.  
  3508. pascal void TNumberText::Initialize(void) // override 
  3509. {
  3510.     inherited::Initialize();
  3511.  
  3512.     fMaximum = MAXLONGINT;
  3513.     fMinimum = 0;
  3514. }
  3515.  
  3516. //--------------------------------------------------------------------------------------------------
  3517. #pragma segment DlgOpen
  3518.  
  3519. pascal void TNumberText::INumberText(TView* itsSuperView,
  3520.                                        const VPoint& itsLocation, 
  3521.                                      const VPoint& itsSize,
  3522.                                        long itsValue, 
  3523.                                      long itsMinimum, 
  3524.                                      long itsMaximum)
  3525. {
  3526.     this->IEditText(itsSuperView, itsLocation, itsSize, 255);
  3527. #if qDebug
  3528.     if (itsMinimum > itsMaximum)
  3529.         cout << "Minimum value specified is greater than maximum for TNumberText.\n";
  3530. #endif
  3531.     fMinimum = itsMinimum;
  3532.     fMaximum = itsMaximum;
  3533.  
  3534.     this->SetValue(itsValue, kDontRedraw);
  3535. }
  3536.  
  3537. //--------------------------------------------------------------------------------------------------
  3538. #pragma segment DlgOpen
  3539.  
  3540. pascal void TNumberText::IRes(TDocument* ,
  3541.                                  TView* itsSuperView,
  3542.                                 Ptr& itsParams) // override 
  3543. {
  3544.     inherited::IRes(NULL, itsSuperView, itsParams);
  3545.  
  3546.     NumberTextTemplate& templateData = (NumberTextTemplate&) *itsParams;
  3547.  
  3548. #if qDebug
  3549.     if (templateData.minimum > templateData.maximum)
  3550.         cout << "Minimum value specified is greater than maximum for TNumberText.\n";
  3551. #endif
  3552.     fMinimum = templateData.minimum;    
  3553.     fMaximum = templateData.maximum;
  3554.  
  3555.     this->SetValue( templateData.value, kDontRedraw);
  3556.  
  3557.     OffsetPtr(itsParams, sizeof(NumberTextTemplate));
  3558. }
  3559.  
  3560. //--------------------------------------------------------------------------------------------------
  3561. #pragma segment MAWriteRes
  3562.  
  3563. pascal void TNumberText::WRes(ViewRsrcHandle theResource,
  3564.                                  Ptr& itsParams) // override 
  3565.  
  3566. {
  3567.     inherited::WRes(theResource, itsParams);
  3568.  
  3569.     NumberTextTemplate&    templateData =
  3570.         (NumberTextTemplate&) *(ExpandPtr( (Handle) theResource, itsParams, sizeof(NumberTextTemplate)));
  3571.  
  3572.     templateData.value = this->GetValue();
  3573.     templateData.minimum = fMinimum;
  3574.     templateData.maximum = fMaximum;
  3575. }
  3576.  
  3577. //--------------------------------------------------------------------------------------------------
  3578. #pragma segment MAWriteRes
  3579.  
  3580. pascal void TNumberText::WriteRes(ViewRsrcHandle theResource,
  3581.                                      Ptr& itsParams) // override 
  3582. {
  3583.     gWResSignature = 'nmbr'; gWResType = "TNumberText";
  3584.     WRes(theResource, itsParams);
  3585. }
  3586.  
  3587. //--------------------------------------------------------------------------------------------------
  3588. #pragma segment DlgRes
  3589.  
  3590. pascal long TNumberText::GetValue(void)
  3591. {
  3592.     Str255        aString;
  3593.     long        theValue;
  3594.  
  3595.     this->GetText(aString);
  3596.     StringToNum(aString, theValue);
  3597.     return theValue;
  3598. }
  3599.  
  3600. //--------------------------------------------------------------------------------------------------
  3601. #pragma segment DlgNonRes
  3602.  
  3603. pascal void TNumberText::SetValue(long newValue,
  3604.                                      Boolean redraw)
  3605. {
  3606.     Str255        aString;
  3607.  
  3608.     newValue = Max(fMinimum, Min(fMaximum, newValue));
  3609.     NumToString(newValue, aString);
  3610.     this->SetText(aString, redraw);
  3611. }
  3612.  
  3613. //--------------------------------------------------------------------------------------------------
  3614. #pragma segment DlgNonRes
  3615.  
  3616. pascal long TNumberText::Validate(void) // override 
  3617. {
  3618.     Str255        theString;
  3619.     decimal        decRec;
  3620.     extended    extValue;
  3621.     short        index;
  3622.     short        validPrefix = 0;
  3623.     long        result;
  3624.  
  3625.     
  3626.     result = kValidValue;
  3627.  
  3628.     //!!! This really begs for a fRequired field to test when the string is left empty 
  3629.     // Then we would inform the user that an empty string is not a valid option. 
  3630.     // Also a fDefault field is necessary. GetValue would return fDefault rather 
  3631.     // than 0 when the string is empty.    For now (2.0) we will not validate an empty
  3632.     // string and assume that if the user wants a value they will override. 
  3633.  
  3634.     this->GetText(theString);
  3635.     if (theString != "")
  3636.     {
  3637.         index = 1;
  3638.         str2dec( p2cstr(&theString), index, decRec, validPrefix); //!!! Note p2cstr
  3639.         if (validPrefix && (index > theString.Length()) && (decRec.exp >= 0))
  3640.         {
  3641.             extValue = dec2num(decRec);
  3642.             if (extValue < fMinimum)
  3643.                 result = kValueTooSmall;
  3644.             else 
  3645.                 if (extValue > fMaximum)
  3646.                     result = kValueTooLarge;
  3647.         }        
  3648.         else
  3649.             result = kNonNumericCharacters;
  3650.     }
  3651.     return result;
  3652. }
  3653.  
  3654. //--------------------------------------------------------------------------------------------------
  3655. #pragma segment DlgFields
  3656.  
  3657. pascal void TNumberText::Fields(TObject* obj) // override 
  3658. {
  3659.     obj->DoToField("TNumberText", NULL, bClass);
  3660.     obj->DoToField("fMinimum", &fMinimum, bLongInt);
  3661.     obj->DoToField("fMaximum", &fMaximum, bLongInt);
  3662.  
  3663.     inherited::Fields(obj);
  3664. }
  3665.  
  3666. //--------------------------------------------------------------------------------------------------
  3667. #pragma segment DlgInit
  3668.  
  3669. pascal void TFloatingTEManager::Initialize(void) // override 
  3670. {
  3671.     inherited::Initialize();
  3672.     fCache = NULL;
  3673. }
  3674.  
  3675. //--------------------------------------------------------------------------------------------------
  3676. #pragma segment DlgClose
  3677. pascal void TFloatingTEManager::Free(void) // override 
  3678. {
  3679.     if (fCache != NULL)
  3680.         fCache = (TDialogTEView*)(FreeIfObject(fCache));
  3681.     inherited::Free();
  3682. }
  3683.  
  3684. //--------------------------------------------------------------------------------------------------
  3685. #pragma segment DlgFields
  3686. pascal void TFloatingTEManager::Fields(TObject* obj) // override 
  3687. {
  3688.     obj->DoToField("TFloatingTEManager", NULL, bClass);
  3689.     obj->DoToField("fCache", &fCache, bObject);
  3690.  
  3691.     inherited::Fields(obj);
  3692. }
  3693.  
  3694. //--------------------------------------------------------------------------------------------------
  3695. #pragma segment DlgRes
  3696. pascal TDialogTEView* TFloatingTEManager::AquireFloatingTE(void)
  3697. {
  3698.     TDialogTEView* result;
  3699.  
  3700.     if (fCache != NULL)    // Got one in the cache!  
  3701.     {
  3702.         result = fCache;
  3703.         fCache = NULL;        // Cache is now empty 
  3704.     }    
  3705.     else
  3706.         result = this->MakeDialogTEView();
  3707.     return result;
  3708. }
  3709.  
  3710. //--------------------------------------------------------------------------------------------------
  3711. #pragma segment DlgRes
  3712.  
  3713. pascal TDialogTEView* TFloatingTEManager::MakeDialogTEView(void)
  3714. {
  3715.     TDialogTEView*    aDialogTEView = NULL;
  3716.  
  3717.     if (qTemplateViews && (gApplication != NULL))
  3718.         aDialogTEView = (TDialogTEView*)(gApplication->DoCreateViews(NULL, NULL, kDialogTEViewID, gZeroVPt));
  3719.     else
  3720.     {
  3721.         aDialogTEView = new TDialogTEView;
  3722.         aDialogTEView->IDialogTEView(NULL, NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable,
  3723.                                     gZeroVRect, gSystemStyle, teFlushDefault, kWithoutStyle, False);
  3724.     
  3725.     }
  3726.     aDialogTEView->fMinAhead = 1;    /* Don't _jump_ the view ahead when
  3727.                                     autoscrolling for scrollselectionintoview
  3728.                                     */
  3729.     return aDialogTEView;
  3730. }
  3731.  
  3732. //--------------------------------------------------------------------------------------------------
  3733. #pragma segment DlgRes
  3734. pascal void TFloatingTEManager::ReleaseFloatingTE(TDialogTEView* aDialogTEView)
  3735. {
  3736.     if (fCache == NULL)
  3737.         fCache = aDialogTEView;
  3738.     else
  3739.         aDialogTEView->Free();
  3740. }
  3741.